virtualenv on Windows

122 views
Skip to first unread message

Mike Dewhirst

unread,
Jan 28, 2014, 9:56:34 PM1/28/14
to django...@googlegroups.com
A little while ago I suggested to someone using Windows to implement
virtualenv "later". So I thought I'd document my experience here.

In summary, it probably works well if you have Visual Studio. The
process outlined below shows a clumsy workaround if you don't.

Hope it helps someone

Mike

- - - - - -

$pip install virtualenv # first step (requires pip obviously)

$mkdir c:\users\miked\env

$virtualenv --no-site-packages c:\users\miked\env\proj-x
New python executable in c:\users\miked\env\proj-x\Scripts\python.exe
Installing setuptools, pip...done.

Now copy your "myproject-x" into c:\users\miked\env\proj-x\myproject-x

At this point on Linux one would install virtualenv-wrapper but that is
unfortunately not available for Windows so a simple workaround is ...

1. mkdir \users\miked\bin # could be anything eg \users\miked\bat

2. Add C:\users\miked\bin to the path environment variable

3. Create a batch file called C:\users\miked\bin\proj-x.bat containing:

cd \users\miked\env\proj-x\myproject-x
..\Scripts\activate

4. Create another batch file
C:\users\miked\env\proj-x\myproject-x\exit.bat containing:

cd \users\miked\
\users\miked\env\proj-x\Scripts\deactivate

5. Test the workaround by opening a command prompt somewhere and
entering proj-x. You should see:

C:\Documents and Settings\Mike Dewhirst\Desktop>cd
\users\miked\env\proj-x\myproject-x

C:\users\miked\env\proj-x\myproject-x>..\Scripts\activate
(proj-x) C:\users\miked\env\proj-x\myproject-x>

6. Test the exit batch file by entering exit at that command prompt:

C:\users\miked\env\proj-x\myproject-x>..\Scripts\activate
(proj-x) C:\users\miked\env\proj-x\myproject-x>exit

(proj-x) C:\users\miked\env\proj-x\myproject-x>cd \users\miked\

(proj-x) C:\users\miked>\users\miked\env\proj-x\Scripts\deactivate
C:\users\miked>

This should let you get into and out of the virtualenv quite easily.

Now comes the difficult bit for Windows - installing stuff in the new
Python's site-packages. First, though, discover what you already have
installed in your main site-packages:

pip freeze > requirements.txt # lists existing site-packages

Here is mine, most of which I don't want in proj-x

Django==1.5.4
Jinja2==2.7.1
MarkupSafe==0.18
Pygments==1.6
South==0.7.6
Sphinx==1.1.3
coverage==3.7
django-discover-runner==1.0
docutils==0.9.1
filemov==1.1.1-2728-py2.7
pillow==2.3.0
pss==1.38
psycopg2==2.4.5
py2exe==0.6.9
pytz==2012h
pywin32==218
virtualenv==1.11.2

So I edit it down to the following, create a directory and save it as
C:\users\miked\env\proj-x\requirements\requirements.txt

Django==1.5.4
South==0.7.6
coverage==3.7
django-discover-runner==1.0
pillow==2.3.0
psycopg2==2.4.5
pytz==2013.9

pip install -r C:\users\miked\env\proj-x\requirements\requirements.txt

And this where (my) problems start. First pip will download the packages
successfully but I don't have Visual Studio installed so those packages
requiring compilation don't get installed. Here is a snippet of pip
output after the downloads:

Installing collected packages: Django, South, coverage,
django-discover-runner, pillow, psycopg2, pytz
Running setup.py install for Django

... and so on until errors start to appear. In my case the signal is:

error: Unable to find vcvarsall.bat

Afterwards, pip freeze shows:

(proj-x) C:\users\miked\env\proj-x>pip freeze
Django==1.5.4
South==0.7.6
coverage==3.7
django-discover-runner==1.0

... which indicates pillow, psycopg2 and pytz did not install.

But how come they were installed in the main site-packages? That's
because they were originally downloaded from
http://www.lfd.uci.edu/~gohlke/pythonlibs/ and installed manually.

However, even after downloading from that site they cannot be installed
manually into a virtualenv! Only pip can do that. The only workaround I
have found is to manually copy them from the main site-packages to the
new virtualenv site-packages. Clumsy.

My proj-x requirements.txt file now looks like this ...

Django==1.5.4
South==0.7.6
coverage==3.7
django-discover-runner==1.0
# pillow==2.3.0 http://www.lfd.uci.edu/~gohlke/pythonlibs/
# psycopg2==2.4.5 http://www.lfd.uci.edu/~gohlke/pythonlibs/
# pytz==2013.9 http://www.lfd.uci.edu/~gohlke/pythonlibs/

After the above clumsy workaround everything works well and pip freeze
displays ...

Django==1.5.4
South==0.7.6
coverage==3.7
django-discover-runner==1.0
pillow==2.3.0
psycopg2==2.4.5
pytz==2013.9



Sam Lai

unread,
Jan 28, 2014, 10:23:50 PM1/28/14
to django-users
> However, even after downloading from that site they cannot be installed manually into a virtualenv! Only pip can do that.

You can install the packages from
http://www.lfd.uci.edu/~gohlke/pythonlibs/ by simply running -

pip install <path to the .exe file>

... from inside your virtualenv. Those .exe files are pip-compatible
ZIP archives
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/52E86DE2.5010907%40dewhirst.com.au.
> For more options, visit https://groups.google.com/groups/opt_out.

Mike Dewhirst

unread,
Jan 29, 2014, 12:27:42 AM1/29/14
to django...@googlegroups.com
On 29/01/2014 2:23pm, Sam Lai wrote:
>> However, even after downloading from that site they cannot be installed manually into a virtualenv! Only pip can do that.
>
> You can install the packages from
> http://www.lfd.uci.edu/~gohlke/pythonlibs/ by simply running -
>
> pip install <path to the .exe file>

I did try that earlier but had no luck. Maybe I got the incantation wrong?

(proj-x) C:\users\miked\env\proj-x>pip install
C:\install_kits\python\postgresql\psycopg2-2.4.5.win32-py2.7.exe

Exception:
Traceback
...
ValueError: ('Missing distribution spec',
'\\install_kits\\python\\postgresql\\psycopg2-2.4.5.win32-py2.7.exe')

Mike

Sam Lai

unread,
Jan 29, 2014, 3:10:00 AM1/29/14
to django-users
Oops, my memory failed me. They don't work with pip, but they do work
with easy_install, which virtualenvs have as well (at least mine do).

http://stackoverflow.com/a/5442340/150999

For example,

easy_install C:\Users\sam\Downloads\Pygments-1.6.win-amd64-py2.7.exe
> https://groups.google.com/d/msgid/django-users/52E8914E.6020107%40dewhirst.com.au.

Mike Dewhirst

unread,
Jan 29, 2014, 6:48:59 PM1/29/14
to django...@googlegroups.com
On 29/01/2014 7:10pm, Sam Lai wrote:
> Oops, my memory failed me. They don't work with pip, but they do work
> with easy_install, which virtualenvs have as well (at least mine do).
>
> http://stackoverflow.com/a/5442340/150999
>
> For example,
>
> easy_install C:\Users\sam\Downloads\Pygments-1.6.win-amd64-py2.7.exe

Thanks Sam - I'll rework my experience :)

Mike Dewhirst

unread,
Feb 3, 2014, 5:11:44 AM2/3/14
to django...@googlegroups.com
On 29/01/2014 7:10pm, Sam Lai wrote:
> Oops, my memory failed me. They don't work with pip, but they do work
> with easy_install, which virtualenvs have as well (at least mine do).
>
> http://stackoverflow.com/a/5442340/150999
>
> For example,
>
> easy_install C:\Users\sam\Downloads\Pygments-1.6.win-amd64-py2.7.exe

Yes - that works. I have now reworked reality into a complex
interlocking web of batch scripts which would be embarrassing to show.

However, this evening at the Melbourne PUG meeting I heard about
Anaconda which apparently make virtualenv passé. Haven't looked at it
yet. Might be a day or so ...

Cheers

Mike

CLIFFORD ILKAY

unread,
Feb 3, 2014, 5:38:53 AM2/3/14
to django...@googlegroups.com
On 02/03/2014 05:11 AM, Mike Dewhirst wrote:
>
> However, this evening at the Melbourne PUG meeting I heard about
> Anaconda which apparently make virtualenv passé. Haven't looked at it
> yet. Might be a day or so ...

That's an unfortunate choice of a name for a Python related project
given that the Fedora/Red Hat installer is called Anaconda and is
written in Python.

--
Regards,

Clifford Ilkay

647-778-8696

Dinamis

<http://dinamis.com>

werefrog

unread,
Feb 3, 2014, 3:37:34 PM2/3/14
to django...@googlegroups.com
Hello,

For Windows, I tried many ways that worked but I finally installed
Visual Studio 2008 C++ for the compilation problems and only pillow and
psycopg2 resist in my case (I simply extract the content of the binaries
from http://www.lfd.uci.edu/~gohlke/pythonlibs/, copy content from
'SCRIPTS' to project's virtualenv 'Scripts' and 'PLATLIB' to project's
virtualven 'Lib/site-packages'; I'll give a try to the easy_install with
them, thank you).

While speaking of psycopg2, I spent a ridiculous amount of time
struggling with postgresql installation on Windows to finally discover
that you should stick to ASCII for the password chosen on this platform.
(Yes, I missed some warning).

You can use virtualenvwrapper-win on Windows. The documentation is short
and efficient but here is some basic steps, begining from install:

pip install -U virtualenv
pip install -U virtualenvwrapper-win

You have to set WORKON_HOME environment variable to to directory where
will be grouped your virtualenvs to make it convenient.

Update pip and setuptools:

easy_install -U pip
pip install -U setuptools

Then, create your virtualenv:

mkvirtualenv myproject

Activate the virtualenv (you will then be on %WORKON_HOME%/myproject/):

workon myproject

I keep projects in their own directory independant from virtualenv. To
add your project directory to its virualenv's pythonpath, use the
following command where <path> can be full or relative:

setprojectdir <path>

Now, install your requirements:

pip install -r requirements.txt

You can use cdproject and cdvirtualenv commands to go to project and
virtualenv directories.

To go back to the 'general' environment, just type:

deactivate

Additional details you probably already know: remember to not rely on
the registry to execute your python scripts :) for example:

python manage.py runserver

and not:

manage.py runserver

Edit you virtualenv's Script\activate.bat to add any other specific
environment variables and don't forget .pth files for specific python path.

That's all for today!

Regards,
Michel

Mike Dewhirst

unread,
Feb 3, 2014, 6:10:40 PM2/3/14
to django...@googlegroups.com
Michel

I learned quite a lot and appreciate it greatly!

Thankyou

Mike

Nick Santos

unread,
Feb 3, 2014, 6:39:01 PM2/3/14
to django...@googlegroups.com
FYI, virtualenvwrapper was ported to windows: https://pypi.python.org/pypi/virtualenvwrapper-win

It works seamlessly like the linux/OSX versions
-Nick



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Mike Dewhirst

unread,
Feb 3, 2014, 7:30:05 PM2/3/14
to django...@googlegroups.com
Thanks Nick

All this goodness is coming to light just I have (almost) given up
Windows altogether. I only need to persuade one more person on my
network to walk away from Microsoft and I'm free! FREE!

Sob ...

Mike

On 4/02/2014 10:39am, Nick Santos wrote:
> FYI, virtualenvwrapper was ported to windows:
> https://pypi.python.org/pypi/virtualenvwrapper-win
>
> It works seamlessly like the linux/OSX versions
> -Nick<mailto:ni...@enviroconsumer.org>
>
>
>
> On Mon, Feb 3, 2014 at 3:10 PM, Mike Dewhirst <mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au>> wrote:
>
> Michel
>
> I learned quite a lot and appreciate it greatly!
>
> Thankyou
>
> Mike
>
>
> On 4/02/2014 7:37am, werefrog wrote:
>
> Hello,
>
> For Windows, I tried many ways that worked but I finally installed
> Visual Studio 2008 C++ for the compilation problems and only pillow
> and psycopg2 resist in my case (I simply extract the content of the
> binaries from http://www.lfd.uci.edu/~__gohlke/pythonlibs/
> <http://www.lfd.uci.edu/~gohlke/pythonlibs/>, copy content from
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>. To post to this
> group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>. Visit this group at
> http://groups.google.com/__group/django-users
> <http://groups.google.com/group/django-users>. To view this
> discussion on the web visit
> https://groups.google.com/d/__msgid/django-users/52F021F0.__1050004%40dewhirst.com.au
>
>
<https://groups.google.com/d/msgid/django-users/52F021F0.1050004%40dewhirst.com.au>.
>
> For more options, visit https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
> -- You received this message because you are subscribed to the Google
> Groups "Django users" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> django-users...@googlegroups.com. To post to this group,
> send email to django...@googlegroups.com. Visit this group at
> http://groups.google.com/group/django-users. To view this discussion
> on the web visit
> https://groups.google.com/d/msgid/django-users/CAM1S3vC2v9Hb-PgMZXwH0N_yTzZdy1TgcJ7X20VGNu-8mMatvA%40mail.gmail.com.

Avraham Serour

unread,
Feb 4, 2014, 1:31:26 AM2/4/14
to django...@googlegroups.com

You can easily install pillow on windows using 'easy_install pillow' it comes with the necessary binaries and you don't need to compile

On Feb 4, 2014 2:30 AM, "Mike Dewhirst" <mi...@dewhirst.com.au> wrote:
Thanks Nick

All this goodness is coming to light just I have (almost) given up Windows altogether. I only need to persuade one more person on my network to walk away from Microsoft and I'm free! FREE!

Sob ...

Mike

On 4/02/2014 10:39am, Nick Santos wrote:
FYI, virtualenvwrapper was ported to windows:
https://pypi.python.org/pypi/virtualenvwrapper-win

It works seamlessly like the linux/OSX versions
<mailto:django-users@googlegroups.com>. Visit this group at

For more options, visit https://groups.google.com/__groups/opt_out
<https://groups.google.com/groups/opt_out>.


-- You received this message because you are subscribed to the Google
 Groups "Django users" group. To unsubscribe from this group and stop
receiving emails from it, send an email to
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Mike Dewhirst

unread,
Feb 4, 2014, 2:00:10 AM2/4/14
to django...@googlegroups.com
On 4/02/2014 5:31pm, Avraham Serour wrote:
> You can easily install pillow on windows using 'easy_install pillow' it
> comes with the necessary binaries and you don't need to compile

Bingo! Yes - it puts it in an egg.

Thanks Avraham


>
> On Feb 4, 2014 2:30 AM, "Mike Dewhirst" <mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au>> wrote:
>
> Thanks Nick
>
> All this goodness is coming to light just I have (almost) given up
> Windows altogether. I only need to persuade one more person on my
> network to walk away from Microsoft and I'm free! FREE!
>
> Sob ...
>
> Mike
>
> On 4/02/2014 10:39am, Nick Santos wrote:
>
> FYI, virtualenvwrapper was ported to windows:
> https://pypi.python.org/pypi/__virtualenvwrapper-win
> <https://pypi.python.org/pypi/virtualenvwrapper-win>
>
> It works seamlessly like the linux/OSX versions
> -Nick<mailto:nick@__enviroconsumer.org
> <mailto:ni...@enviroconsumer.org>>
>
>
>
> On Mon, Feb 3, 2014 at 3:10 PM, Mike Dewhirst
> <mi...@dewhirst.com.au <mailto:mi...@dewhirst.com.au>
> <mailto:mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au>>__> wrote:
>
> Michel
>
> I learned quite a lot and appreciate it greatly!
>
> Thankyou
>
> Mike
>
>
> On 4/02/2014 7:37am, werefrog wrote:
>
> Hello,
>
> For Windows, I tried many ways that worked but I finally installed
> Visual Studio 2008 C++ for the compilation problems and only pillow
> and psycopg2 resist in my case (I simply extract the content of the
> binaries from http://www.lfd.uci.edu/~____gohlke/pythonlibs/
> <http://www.lfd.uci.edu/~__gohlke/pythonlibs/>
> django-users+unsubscribe@__goo__glegroups.com
> <http://googlegroups.com>
> <mailto:django-users%__2Buns...@googlegroups.com
> <mailto:django-users%252Buns...@googlegroups.com>__>. To
> post to this
> group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>
> <mailto:django-users@__googlegroups.com
> <mailto:django...@googlegroups.com>>. Visit this group at
> http://groups.google.com/____group/django-users
> <http://groups.google.com/__group/django-users>
> https://groups.google.com/d/____msgid/django-users/52F021F0.____1050004%40dewhirst.com.au
> <https://groups.google.com/d/__msgid/django-users/52F021F0.__1050004%40dewhirst.com.au>
> https://groups.google.com/____groups/opt_out
> <https://groups.google.com/__groups/opt_out>
> <https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>>.
>
>
> -- You received this message because you are subscribed to the
> Google
> Groups "Django users" group. To unsubscribe from this group
> and stop
> receiving emails from it, send an email to
> django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>. To post to
> this group,
> send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>. Visit this group at
> https://groups.google.com/d/__msgid/django-users/__CAM1S3vC2v9Hb-PgMZXwH0N___yTzZdy1TgcJ7X20VGNu-8mMatvA%__40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAM1S3vC2v9Hb-PgMZXwH0N_yTzZdy1TgcJ7X20VGNu-8mMatvA%40mail.gmail.com>.
>
>
> For more options, visit https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users+unsubscribe@__googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/__group/django-users
> <http://groups.google.com/group/django-users>.
> To view this discussion on the web visit
> https://groups.google.com/d/__msgid/django-users/52F0348D.__90102%40dewhirst.com.au
> <https://groups.google.com/d/msgid/django-users/52F0348D.90102%40dewhirst.com.au>.
> For more options, visit https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFWa6tJcm6OwEPTqUuWrr2irPDB4aExctF4tT2U7oF5QtH0mLQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages