python - 你如何在 Python 中更正模块已经加载的 UserWarnings?

标签 python warnings virtualenv distribute

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

/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

我认为这与使用分布式和 virtualenv 的组合有关,但想检查是否有其他人遇到过此问题或知道如何修复它。

最佳答案

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

在创建 virtualenv 时使用 --no-site-packages 可以防止系统包之间的任何冲突。在创建新的 virtualenv 时,我几乎总是使用该选项来防止任何冲突。虽然我可能有几个库副本,但至少它们不会相互混淆。

关于python - 你如何在 Python 中更正模块已经加载的 UserWarnings?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3861336/

相关文章:

r - 如何禁用 R 警告 : timezone of object (UTC) is different than current timezone ()

linux - 使用 apt 在 Linux 上安装 virtualenv 的权限问题

django - Virtualenv - 清理未使用的软件包安装

python - 如何防止VLAN标记从套接字接收的数据包中剥离?

python - 'await future' 和 'await asyncio.wait_for(future, None)' 之间有区别吗?

python - 从链表中删除特定节点 - python

python - 警告 :tensorflow:AutoGraph could not transform <function _preprocess at 0x7f8ff80cd160> and will run it as-is

javascript - 意外值对齐解析 preserveAspectRatio 属性 Firefox 错误

python - 即使我已经通过 pip 安装了 'flask_wtf' 和 'wtforms',但仍无法在虚拟环境中导入它们?

python - instance(object, type) 返回 True,它不应该是 False 吗?