Python 激活虚拟环境不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24011399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Activating a virtual env not working
提问by Hunsu
I created two virtualenv and I installed two different versions of django. Now I have a problem to activate the two environment, I do like this :
我创建了两个 virtualenv 并安装了两个不同版本的 django。现在我在激活两个环境时遇到问题,我是这样的:
source Django1.6/bin/activate
Then I see that the environment was activated. Then I do :
然后我看到环境被激活了。然后我做:
pip install django # for test
and I get this message :
我收到这条消息:
Requirement already satisfied (use --upgrade to upgrade):
django in /usr/local/lib/python2.7/dist-packages
This tell that the environment was not activated but it use the default one. Why I'm getting this?
这表明环境未激活,但使用默认环境。为什么我得到这个?
采纳答案by Hunsu
When changing the environment location we must execute virtualenv
on the new folder.
When looking to activate file I have found this code :
更改环境位置时,我们必须virtualenv
在新文件夹上执行。在寻找激活文件时,我发现了以下代码:
VIRTUAL_ENV="/old/folder"
export VIRTUAL_ENV
This variable will updated when we execute virtualenv
on the new folder.
当我们virtualenv
在新文件夹上执行时,此变量将更新。
回答by Siyaram Malav
Lets say you have got two virtual environments installed venv1and venv2.
假设您已经安装了两个虚拟环境venv1和venv2。
virtualenv venv1
virtualenv venv2
Virtualenv will create the directories and install the relevant Python libraries, PIP, etc.
Virtualenv 将创建目录并安装相关的 Python 库、PIP 等。
Activate each environment one at a time.do your stuff and deactivate.
一次激活一个环境。做你的事并停用。
source venv1/bin/activate
# make changes to the environment. i.e pip install django==1.6.8
deactivate
source venv2/bin/activate
# make changes to the environment. i.e pip install django==1.7.1
deactivate
can check installed django versions.
可以检查已安装的 Django 版本。
source venv1/bin/activate
python
import django
django.VERSION
[. . . . make note of the version of django running . . . .]
deactivate
source venv2/bin/activate
python
import django
django.VERSION
[. . . . make note of the version of django running . . . .]
deactivate
If everything was done correctly you should see a different version of Django running in each virtualenv.
如果一切正常,您应该会看到在每个 virtualenv 中运行的 Django 版本不同。
Hope it helps.
希望能帮助到你。