26

I am having issues with the standard logging module. If I open a python2.7 shell and import logging everything works fine:

$ python
>>> import logging
>>>

But if I open a python3.4 shell and import logging I get the following error:

$ python3.4
>>> import logging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2222, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 2164, in _find_spec
File "<frozen importlib._bootstrap>", line 1940, in find_spec
File "<frozen importlib._bootstrap>", line 1916, in _get_spec
File "<frozen importlib._bootstrap>", line 1897, in _legacy_get_spec
File "<frozen importlib._bootstrap>", line 863, in spec_from_loader
File "<frozen importlib._bootstrap>", line 904, in spec_from_file_location
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/logging-0.4.9.6-py3.4.egg/logging/__init__.py", line 618
raise NotImplementedError, 'emit must be implemented '\
                         ^
SyntaxError: invalid syntax

I have no idea what the problem is and can't seem to find anyone else who has had the same issue.

4 Answers 4

48

logging module is by default there in Python 3 environment .No need to import it.

Sign up to request clarification or add additional context in comments.

2 Comments

Why was this downvoted? It's definitely a correct answer
I was trying to add logging==0.4.9.6 in the requirements file of my gfunc xD, and it didn't even show me the error in the logs.
30

You seem to have installed a third party library called logging in your Python 3 environment, which is hiding the standard library version, and one of its files has a typo.

2 Comments

It's not so much a typo than that it's Python 2 syntax. But yes, that's not the (location of) the built-in logging module.
Thank you both! I deleted logging-0.4.9.6-py3.4.egg from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ and now logging is working in both python2 and python3.
9

I stupidly created a file called logging.py to try out some log features. Then when trying the code below, it is effectively referring to itself and can't find the debug method.

import logging

logging.debug("Debug message")

Changing my file name to logtest.py fixed the problem.

1 Comment

I felt like a clown when I read this and realized that was my issue too. Thank you for sharing!
0

for me it was the previous install of a logging library under an older Python version.

pip3 uninstall logging

fixed it for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.