如何将 virtualenv 与本地 dist 包隔离? [英] how to isolate virtualenv from local dist-packages?
问题描述
如何使用/usr/local/lib/python2.7/dist-packages"停止 virtualenv?
How do you stop virtualenv using '/usr/local/lib/python2.7/dist-packages'?
目前我运行时它
virtualenv --no-site-packages ENV
它仍然使用我希望停止的 dist-packages
it still uses the dist-packages that i wish to stop
/usr/local/lib/python2.7/dist-packages 在 PYTHONPATH 中,其他应用程序需要在那里
/usr/local/lib/python2.7/dist-packages is in the PYTHONPATH, it needs to be there for other apps
推荐答案
您的编辑解释了您正在观察的行为.
Your edit explains the behaviour you are observing.
您需要在激活 virtualenv 时取消设置 PYTHONPATH
.
You need to unset PYTHONPATH
when activating the virtualenv.
unset PYTHONPATH
source /path/to/virtualenv/bin/activate
virtualenv --no-site-packages ENV
创建一个空的 virtualenv 就好了,但是您的 PYTHONPATH
导出会使您的空 virtualenv 无效.
virtualenv --no-site-packages ENV
creates an empty virtualenv just fine, but your PYTHONPATH
export nullifies your empty virtualenv.
为了使事情更简单,您可以编辑 activate
脚本并在那里添加 unset PYTHONPATH
命令.如果您想在停用 virtualenv 后恢复原始 PYTHONPATH,您还需要修改该文件中的 deactivate
函数.
In order to make things simpler you can just edit the activate
script and add the unset PYTHONPATH
command there. If you want to restore the original PYTHONPATH upon deactivating the virtualenv you also need to modify the deactivate
function in that file.
这篇关于如何将 virtualenv 与本地 dist 包隔离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!