Adventures in Freelancing
How to Quickly Open Virtualenvs on Windows
I develop on both Windows and Linux. In fact, I often work on the same projects in both environments.
In general, I find both environments to be mostly the same, as far as Python development is concerned. Mostly the same that is, except that virtualenvwrapper isn’t available on windows.
If you’re not familiar with virtualenvwrapper, it is a brilliant shell script that makes virtualenv super easy to work with. I highly recommend it (except of course if you’re on Windows)
One of the best things about virtualenvwrapper is it lets you quickly and easily activate any available virtualenv with the `workon` command.
$ workon virtualenv_name (virtualenv_name)/path/to/project/dir/$
Not only does it activate the environment, but it will also automatically ‘cd’ you to the project’s working directory. You have to set the up manually but it is super simple, just add the ‘cd’ command to the ‘postactivate’ hook that virtualenvwrapper sets up in the virtualenv’s directory.
So, no virtualenvwrapper for Windows, but there are other ways to get a command shell which is already good to go for a given project.
In fact, it only takes a simple shortcut to cmd.exe with a few arguments. Create a new shortcut using the right-click context menu, then set
- Target: %windir%\system32\cmd.exe /k “c:\path\to\env\Scripts\activate”
- Start In: c:\path\to\project\dir
The /k switch runs the activate script in the same shell, instead of starting a new shell.
Another approach is to simply create a batch script on your path, which first cd’s to the project directory, then runs the activate script. I personally prefer the shortcut approach, but both are effective.
If you’re using Console2, you have two options. You can use the same approach as above, just replace the path to cmd.exe in your shortcut or batch script with the path to your Console2.exe.
Console2 also lets you define tabs for quickly opening a desired environment. In Edit > Settings > Tabs, click Add:
There is a slight twist – you need to specify an executable in the shell argument, you can’t just put the path to the activate script or you’ll get an error.
| Print article | This entry was posted by clawlor on June 7, 2010 at 10:59 am, and is filed under Dev Tools, Python. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

