Module pytz was already imported

给你一囗甜甜゛ 提交于 2019-11-27 16:55:13

问题


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?


回答1:


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.




回答2:


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__



回答3:


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.



来源:https://stackoverflow.com/questions/7239518/module-pytz-was-already-imported

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!