Module pytz was already imported
I keep getting the following error while running Python code:
C:\Python26\lib\site-packages\pytz\__init__.py:32: UserWarning: Module pytz was already imported from C:\Python26\lib\site-packages\pytz\__init__.pyc, but c:\python26\lib\site-packages\pytz-2011h-py2.6.egg is being added to sys.path from pkg_resources import resource_stream开发者_运维知识库
What does it mean and how can I solve it?
You've got the package installed in pytz
and also as a .egg
. Remove the .egg
and you won't get the warning.
However, note that it's referred to as a "spurious warning" -- this isn't actually a problem, though it could become one if the two were different.
From the Python bugtracker issue:
It appears that a big source of spurious warnings for this is when pkg_resources is imported after other modules found in eggs. This can be resolved by changing the insert_on() method to only check conflicts when the distribution isn't already on sys.path. In other words, if you're re-adding something that's already there, there's no point in getting the warning more than once.
To see what going on with the importations, just write this script and check the output. It can give you some useful informations:
import sys, setuptools, pkg_resources
print sys.path
print pkg_resources.__file__
print setuptools.__file__
I had the following problem:
/Users/rkiko/anaconda/lib/python2.7/site-packages/pytz/__init__.py:29: UserWarning: Module pytz
was already imported from /Users/rkiko/anaconda/lib/python2.7/site-packages/pytz/__init__.pyc, but
/Library/Python/2.7/site-packages is being added to sys.path
from pkg_resources import resource_stream
Deleting the entire pytz folder from /Users/rkiko/anaconda/lib/python2.7/site-packages/ fixed it for me. This way only one pytz package is left. The solution is similar to agf's above, but in my case it was not an egg that was disturbing, but a second pytz installation. So, check if you have two installations and delete the one, that is not the systems python installation.
精彩评论