2

I have virtualenv installed on windows.

In cmd, i run python and look at sys.path and see the virtualenv path included.

but when i run manage.py (for django), I don't see the virtualenv path, so virtualenv is not working with django server.

Why?

2
  • stackoverflow won't let me answer my own question, so i'll put the answer here: the solution is to explicitly invoke python by using: python <file>.py . . . as described in velocityreviews.com/forums/… . . . for some reason, the python registered with .py in windows does not invoke virtualenv. Commented Nov 9, 2011 at 17:34
  • 1
    incidentally, this is specific to the Windows shell. I tend to use a bash shell for web dev on Windows, as all the unixy stuff works better: stackoverflow.com/questions/913912/bash-shell-for-windows/… Commented Nov 9, 2011 at 18:04

3 Answers 3

3

the solution is to explicitly invoke python by using: python file.py

as described in http://www.velocityreviews.com/forums/t727997-problems-running-virtualenv-under-windows.html

for some reason, the python registered with .py in windows does not invoke virtualenv.

Sign up to request clarification or add additional context in comments.

1 Comment

If you run .py file directly from Windows CLI, it uses global association information found in registry to find the application for the desired file name extension. It will find Python interpreter in the global location and will use it. To run .py files directly using your virtualenv, you could change the association in the activate script, but that change would be global, which pretty much kills the whole idea of using virtual environments for Python development.
1

Virtualenv modifies the PATH to include a Python with the correct setup. It's a completely separate program from the system Python.

The PATH is used to look up programs by name: the first program of a given name that's in the PATH gets executed.

When you “run a file”, Windows uses the extension of the file to look up a program to run. It doesn't look it up by the name of the program, and so doesn't check the PATH.

The solution is to explicitly invoke Python from the command line (python manage.py) while a virtualenv is active. This way, Windows will search PATH for what you meant by “python”, and find the correct one.

Comments

0

have you done:

> source ../path-to/bin/activate

?

1 Comment

It is \path-to-env\Scripts\activate.bat on Windows, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.