For Python app developers, its a common practice to use virtual environments.
Virtualenvwrapper is a tool to conveniently work with virtual environments. As the name implies, it is a wrapper over
virtualenv. The following setup has been tested on MacOS Catalina however it should also work on other versions with a little or no modifications.
Setup time (approx.) 30 minutes.
- Install Homebrew, if you don’t have it already.
There are other possibilities as well to install Python3 but I recommend installing it via Homebrew for cleaner installation and easier maintenance (upgrade etc).
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- Install Python3
brew install python3
pip3 also gets installed automatically with above command.
- Install Virtualenvwrapper
sudo -H pip3 install virtualenvwrapper
- In .zshrc (or bashrc), add following lines:
In your home directory, you’ll find one of the two;
.bashrcdepending on the shell you use. If there is no such file, please create one (again according to the shell you use).
Please note that Mac Catalina uses Zsh by default.
- Load the new configuration
- Create a virtual environment
You should be able to use following command without error:
test-env should have been created and activated.
PS: You can remove the test-env, if you don’t want to keep it, with command:
- Activate a virtual environment / Switch between virtual environments
If you have
test-env-2created, you can switch between these two using
- Deactivate the current virtual environment
- Remove a virtual environment