如何在已经创建的virtualenv中设置pythonpath? [英] How do you set your pythonpath in an already-created virtualenv?

查看:310
本文介绍了如何在已经创建的virtualenv中设置pythonpath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要编辑什么文件,如何编辑?我创建了一个虚拟环境.

What file do I edit, and how? I created a virtual environment.

推荐答案

EDIT#2

正确的答案是 @arogachev的那个.

如果要更改virtualenv中使用的PYTHONPATH,可以将以下行添加到virtualenv的bin/activate文件中:

If you want to change the PYTHONPATH used in a virtualenv, you can add the following line to your virtualenv's bin/activate file:

export PYTHONPATH="/the/path/you/want"

这样,每次使用此virtualenv时都会设置新的PYTHONPATH.

This way, the new PYTHONPATH will be set each time you use this virtualenv.

(回答@RamRachum的评论)

要将其恢复到deactivate上的原始值,可以添加

To have it restored to its original value on deactivate, you could add

export OLD_PYTHONPATH="$PYTHONPATH"

在前面提到的行之前,然后将以下行添加到您的bin/postdeactivate脚本中.

before the previously mentioned line, and add the following line to your bin/postdeactivate script.

export PYTHONPATH="$OLD_PYTHONPATH"

这篇关于如何在已经创建的virtualenv中设置pythonpath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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