I have installed virtualenv 1.10 on a Windows 7 machine with Python 2.7 on it.
I have created a virtual env called TESTENV. It is located in C:\
If I run C:\TESTENV\Scripts\activate
and then type python
followed by:
import sys
print sys.prefix
it outputs C:\TESTENV
, as 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
.
I tried adding a shebang line to the script but that doesn't work on 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.When you installed Python, the installation associated
.py
and.pyw
files with appropriateC:\Python27\python.exe
andC:\Python27\pythonw.exe
applications. So when you run (in your cmd) onlyD:\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. In this case that is the previously installedC:\Python27\python.exe
.virtualenv
activate
only adds that particular virtual environments python interpreter at the start of thePATH
environment variable, so when you typepython
incmd
you will get the appropriatepython.exe
executed.So the solution to your problem is to run your script as:
After you activated the environment.