Tested under zsh
, should work under bash
too.
-
Install
virtualenv
&virtualenvwrapper
. Depends on the distribution. -
Put in
.zshrc
(.bashrc
if you usebash
):# Virtualenvs if which virtualenvwrapper.sh &> /dev/null; then mkdir -p $HOME/Prog export WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/Prog/venvs source $(which virtualenvwrapper.sh) fi
-
Create a new virtualenv using the command
mkproject project_name
(obviously you will changeproject_name
to something meaningful). -
Now the virtualenv is activated and you have cd-ed into
$PROJECT_HOME/$project_name
. You can start your development (e.g. install packages usingpip install package_name
etc). -
When you are done you just write
deactivate
. This will restore the default python installation into use. -
If you want to remove a virtualenv you write
rmvirtualenv project_name
. This will delete the$HOME/.virtualenvs/$project_name
directory but not the$HOME/Prog/venvs/$project_name
one. I.e. your code is safe! -
The
mkproject
command uses the default python installation. This may be python2 or python3 depending on the distribution. You can explicitly specify a python version usingmkproject -p /usr/bin/python3 project_name
.