How do you correct Module already loaded UserWarnings in Python?

后端 未结 5 582
星月不相逢
星月不相逢 2021-01-01 16:48

Getting the following kinds of warnings when running most python scripts in the command line:

/Library/Python/2.6/site-packages/virtualenvwrapper/hook_loader         


        
相关标签:
5条回答
  • 2021-01-01 16:57

    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')  
    
    0 讨论(0)
  • 2021-01-01 17:02

    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.

    0 讨论(0)
  • 2021-01-01 17:06

    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.

    0 讨论(0)
  • 2021-01-01 17:11

    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.

    0 讨论(0)
  • 2021-01-01 17:21

    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.

    0 讨论(0)
提交回复
热议问题