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

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

问题描述

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

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

推荐答案

最优雅的解决这个问题的方法是这里.

The most elegant solution to this problem is here.

原始答案仍然存在,但这是一个凌乱的解决方案:

Original answer remains, but this is a messy solution:

如果您想更改 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天全站免登陆