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?
virtualenvdoesn't change the default application that starts a file.When you installed Python, the installation associated
.pyand.pywfiles with appropriateC:\Python27\python.exeandC:\Python27\pythonw.exeapplications. So when you run (in your cmd) onlyD:\virtualenv_test.py, cmd looks into the registry and finds the application that is associated with.pyfiles and then runs the file with that application. In this case that is the previously installedC:\Python27\python.exe.virtualenvactivateonly adds that particular virtual environments python interpreter at the start of thePATHenvironment variable, so when you typepythonincmdyou will get the appropriatepython.exeexecuted.So the solution to your problem is to run your script as:
After you activated the environment.