Creating Virtual Environment Mac OS - jordy33/turbogears_tutorial GitHub Wiki

What is virtualenv?
virtualenv is a tool that allows you to create isolated Python environments, which can be quite helpful when you have different projects with differing requirements. As this is the case with TurboGears, it can be indispensable when working on those.
What is virtualenvwrapper?
virtualenvwrapper is just that, a wrapper utility around virtualenv that makes it even easier to work with. I admit that I have never used virtualenv without virtualenvwrapper, and I do not intend to. For that reason this post will only cover working with virtualenv via virtualenvwrapper. Note also that virtualenvwrapper is a set of shell functions that are guaranteed to work in the following shells:
Installation
Both virtualenv and virtualenvwrapper can be installed via pip. Install virtualenv first and then virtualenvwrapper. Use the following commands to install them:
Latest Mac OS Catalina: Update pip
sudo -H pip3 install --upgrade pip
Uninstall virtualenv (Enter like root)
sudo -i
sudo pip uninstall virtualenv
sudo pip uninstall virtualenvwrapper
sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper
exit
Edit ~/.zshrc
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export p3=`which python3`
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
Close the session and restart terminal
Using virtualenvwrapper
There are a lot of commands available with virtualenvwrapper, all of which are well documented. In my experience, the following are the commands you will use most often:
mkvirtualenv - used to create environment
rmvirtualenv - used to remove an existing virtual environment. The environment must be deactivated (see below) before it can be removed.
workon - used to activate a virtual environment. Will also list all existing virtual environments if no argument is passed.
deactivate - used to deactivate the currently active virtual environment. Note that workon will automatically deactivate the current environment before activating a new one.
Note: In order to start using the wrapper you must exit your terminal session and open again to gain access to the commands.
[Back]