如何在Python中更正模块已加载的UserWarnings? [英] How do you correct Module already loaded UserWarnings in Python?

查看:132
本文介绍了如何在Python中更正模块已加载的UserWarnings?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在命令行中运行大多数python脚本时会收到以下警告:

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

/Library/Python/2.6/site-packages/virtualenvwrapper/hook_loader.py:16: UserWarning: Module 

pkg_resources was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
  import pkg_resources

/Library/Python/2.6/site-packages/virtualenvwrapper/hook_loader.py:16: UserWarning: Module site was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
  import pkg_resources

我认为这与使用distribution和virtualenv的组合有关,但是我想检查是否有人遇到了这个问题,或者知道如何解决它.

I think it has to do with a combination of using distribute and virtualenv, but wanted to check if anyone else has run in to this or would know how to go about fixing it.

推荐答案

也许使用virtualenv选项--no-site-packages,所以您不会在虚拟环境中看到任何系统站点程序包.在您的virtualenv和系统根目录中都安装了项目可能是导致此问题的原因.

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.

在创建您的virtualenv时使用--no-site-packages可以防止系统软件包之间发生任何冲突.我几乎总是在创建新的virtualenv时使用该选项,以防止发生任何冲突.尽管我可能有几本库的副本,但至少它们不会互相混淆.

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.

这篇关于如何在Python中更正模块已加载的UserWarnings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆