How do you correct Module already loaded UserWarnings in Python?

*爱你&永不变心* 提交于 2019-11-30 11:09:14

Perhaps use the virtualenv option --no-site-packages so you won't see any system site-packages within your virtual environment. Having items installed both in your virtualenv and on the system root may be the cause of this issue.

Using --no-site-packages when creating your virtualenv prevents any conflict between system packages. I almost always use that option when creating a new virtualenv to prevent any conflicts. Though I may have several copies of libraries, at least they don't mess with each other.

The python equivalent of putting a bit of electrical tape over the check engine light would be to use the -W command line flag or by adding a warning filter.

alephzarro

In my case reinstalling of anything did not help. There were some orphaned .pyc files (specifically pkg_resources.pyc) left in /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python

sudo find . -type f -name "*.pyc" -delete

made it work. This link helped me to track down the problem.

I had this sort of Python packaging hell visit today too.

Running Python 2.7.3 on Ubuntu, using namespace packages and using zc.buildout.

Finally, updating system wide Distribute from older version 0.6.30 to latest version 0.6.35 resolved the problem.

If the warning shows in a program you are modifying, try it this way (examply with pytz):

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