Using VirtualEnv with multiple Python versions on windows

Better:

py -3.4 -m venv c:\path\to\wherever\you\want\it

If you don’t have the py.exe launcher (but it should be installed) you can replace py -3.4 with c:\Python34\python.exe (assuming the default location)


This works because of the handy-dandy, Windows-versioningest, super nice runtime picker py.exe

By default, py.exe will be present on a Windows install (I think it comes with 2.7, I know it does with 3+). When you run py then it will search for some environment variables or you can override that with a specific verison number (in your case -2.7or -3.4) You can leave off the .4 and it will choose the “biggest” minor version number.

You can also use it to run Python scripts. If you put a hash-bang line at the top of your script #!python3 and call it py myscript.py then it will pick the correct version of Python to start with, by searching the first line of the script and searching for a version number.

This is cool, because you can put something like #!/usr/bin/env python3.4 in the top of your script and run it on Windows with py, or on linux by doing

$ chmod +x myscript.py
$ ./myscript.py

Pretty useful.

Leave a Comment