[英]virtualenv activation on windows
I have installed virtualenv 1.10 on a Windows 7 machine with Python 2.7 on it. 我已经在装有Python 2.7的Windows 7机器上安装了virtualenv 1.10。
I have created a virtual env called TESTENV. 我创建了一个名为TESTENV的虚拟环境。 It is located in C:\\ 它位于C:\\
If I run C:\\TESTENV\\Scripts\\activate
and then type python
followed by: 如果我运行C:\\TESTENV\\Scripts\\activate
,然后键入python
后跟:
import sys
print sys.prefix
it outputs C:\\TESTENV
, as exprected. 它输出C:\\TESTENV
,表示为exprected。
But if I run D:\\virtualenv_test.py
(which is a script containing the two lines of code I used above) it outputs C:\\Python27
. 但是如果我运行D:\\virtualenv_test.py
(这是一个包含我上面使用的两行代码的脚本),它会输出C:\\Python27
。
I tried adding a shebang line to the script but that doesn't work on Windows. 我尝试在脚本中添加一个shebang行,但这在Windows上不起作用。
Why is the script not running in the context of the virtual environment? 为什么脚本不在虚拟环境的上下文中运行?
virtualenv
doesn't change the default application that starts a file. virtualenv
不会更改启动文件的默认应用程序。
When you installed Python, the installation associated .py
and .pyw
files with appropriate C:\\Python27\\python.exe
and C:\\Python27\\pythonw.exe
applications. 安装Python时,安装会将.py
和.pyw
文件与适当的C:\\Python27\\python.exe
和C:\\Python27\\pythonw.exe
应用程序相关联。 So when you run (in your cmd) only D:\\virtualenv_test.py
, cmd looks into the registry and finds the application that is associated with .py
files and then runs the file with that application. 因此,当您(在您的cmd中)只运行D:\\virtualenv_test.py
,cmd会查看注册表并找到与.py
文件关联的应用程序,然后使用该应用程序运行该文件。 In this case that is the previously installed C:\\Python27\\python.exe
. 在这种情况下,这是以前安装的C:\\Python27\\python.exe
。
virtualenv
activate
only adds that particular virtual environments python interpreter at the start of the PATH
environment variable, so when you type python
in cmd
you will get the appropriate python.exe
executed. virtualenv
activate
仅在PATH
环境变量的开头添加特定的虚拟环境python解释器,因此当您在cmd
键入python
,您将获得执行的相应python.exe
。
So the solution to your problem is to run your script as: 所以你的问题的解决方案是运行你的脚本:
python D:\virtualenv_test.py
After you activated the environment. 激活环境后。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.