I'm using VirtualEnv on Windows XP. I'm wondering if I have my brain wrapped around it correctly.
I ran virtualenv ENV
and it created C:\WINDOWS\system32\ENV
. I then changed my PATH
variable to include C:\WINDOWS\system32\ENV\Scripts
instead of C:\Python27\Scripts
. Then, I checked out Django into C:\WINDOWS\system32\ENV\Lib\site-packages\django-trunk
, updated my PYTHON_PATH
variable to point the new Django directory, and continued to easy_install
other things (which of course go into my new C:\WINDOWS\system32\ENV\Lib\site-packages
directory).
I understand why I should use VirtualEnv so I can run multiple versions of Django, and other libraries on the same machine, but does this mean that to switch between environments I have to basically change my PATH
and PYTHON_PATH
variable? So, I go from developing one Django project which uses Django 1.2 in an environment called ENV
and then change my PATH
and such so that I can use an environment called ENV2
which has the dev version of Django?
Is that basically it, or is there some better way to automatically do all this (I could update my path in Python code, but that would require me to write machine-specific code in my application)?
Also, how does this process compare to using VirtualEnv on Linux (I'm quite the beginner at Linux).
Normally
virtualenv
creates environments in the current directory. Unless you're intending to create virtual environments inC:\Windows\system32
for some reason, I would use a different directory for environments.You shouldn't need to mess with paths: use the
activate
script (in<env>\Scripts
) to ensure that the Python executable and path are environment-specific. Once you've done this, the command prompt changes to indicate the environment. You can then just invoke easy_install and whatever you install this way will be installed into this environment. Usedeactivate
to set everything back to how it was before activation.Example:
Notice how I didn't need to specify a path for
deactivate
-activate
does that for you, so that when activated "Python" will run the Python in the virtualenv, not your system Python. (Try it - do animport sys; sys.prefix
and it should print the root of your environment.)You can just activate a new environment to switch between environments/projects, but you'll need to specify the whole path for
activate
so it knows which environment to activate. You shouldn't ever need to mess with PATH or PYTHONPATH explicitly.If you use Windows Powershell then you can take advantage of a wrapper. On Linux, the
virtualenvwrapper
(the link points to a port of this to Powershell) makes life withvirtualenv
even easier.Update: Not incorrect, exactly, but perhaps not quite in the spirit of
virtualenv
. You could take a different tack: for example, if you install Django and anything else you need for your site in your virtualenv, then you could work in your project directory (where you're developing your site) with the virtualenv activated. Because it was activated, your Python would find Django and anything else you'd easy_installed into the virtual environment: and because you're working in your project directory, your project files would be visible to Python, too.Further update: You should be able to use
pip
,distribute
instead ofsetuptools
, and just plainpython setup.py install
withvirtualenv
. Just ensure you've activated an environment before installing something into it.in my project wsgi.py file i have this code (it works with virtualenv,django,apache2 in windows and python 3.4)
in virtualhost file conf i have
Yes basically this is what virtualenv do , and this is what the
activate
command is for, from the doc here:so you should just use
activate
command which will do all that for you: