激活/停用 virtualenv 时,我可以自动更改我的 PYTHONPATH 吗? [英] Can I automatically change my PYTHONPATH when activating/deactivating a virtualenv?
问题描述
我想在特定的 virtualenv 中使用与我平常不同的 PYTHONPATH.如何自动设置?我意识到可以破解 bin/activate
文件,有没有更好/更标准的方法?
I would like to have a different PYTHONPATH from my usual in a particular virtualenv. How do I set this up automatically? I realize that it's possible to hack the bin/activate
file, is there a better/more standard way?
推荐答案
这个 django-users post 可能会对你有很大帮助.它建议使用 virtualenvwrapper 来包装 virtualenv,以使用 add2virtualenv 命令.使用它,当环境处于活动状态时,您只需调用:
This django-users post is probably going to help you a lot. It suggests using virtualenvwrapper to wrap virtualenv, to use the add2virtualenv command. Using this, when the environment is active, you can just call:
add2virtualenv directory1 directory2 ...
将目录添加到当前环境的 pythonpath 中.
to add the directories to your pythonpath for the current environment.
它自动处理环境切换上的 PATH 更改.不需要黑魔法.等等!
It handles autonomously the PATH changes on environment switches. No black magic required. Et voila!
这篇关于激活/停用 virtualenv 时,我可以自动更改我的 PYTHONPATH 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!