Python Developers, ever wanted an easier way to create or activate multiple different virtual environments? This is something that has plagued me for sometime.
One option that has been developed and works ok is Anaconda, but that does not work well with internal Pip packages or install packages from source.
An alternative I came across a couple of months ago in a tutorial on setting up Django written by DigitalOcean, has you setup a test repo and a production repo and create an alias workon
that takes a parameter for activating the correct virtual environment.
Why not make workon
able to make a venv?
To make coding this easier, I put a file named workon.bat
in a directory that I have added to my PATH variable (in my case, c:\bin
- a place where I store similar utilities), this makes typing workon
on the command line call this script.
At a high level, the script should:
accept an argument
if none is provided, print useage information and exit
else, store that name
Check if there is a folder locally by that name
if so, call %1\scripts\activate
to activate the venv
Check if there is one in a “global” folder (which I made a config variable at the top of the script)
if so, call %_envs_root%\%1\scripts\activate
to activate it.
If it does not exist in either location, then we need to create it.
I’ve opted to have it prompt (Y/n) to ask for local vs global, aftwards it makes the venv, and activates it and exits.
(Download: Click Here)