To install Python, do the following steps:
- Go to https://www.python.org/downloads/
- Download the latest version, e.g., v3.10.5.
- Double-click the downloaded .pkg (for Mac) file and follow the instructions to install Python.
- After the installation is completed, verify the version by invoking the following command in the command-line tool, e.g., Terminal (on Mac):
python3 -V
- You should see the output reflecting the Python version that you have installed.
Python 3.10.5
Pip is a package management tool for Python libraries. You use pip to easily install/uninstall Python packages. To install pip, do the following steps: Invoke the following command in the command-line tool to install pip:
python3 -m ensurepip -U
If pip is not available on your computer, it will proceed to do the installation. If pip already exists, the command will try to upgrade it to the latest version. After successful installation, you can check your pip version using the following command:
python3 -m pip -V
In the command-line tool, invoke the following command to install the virtual environment software (virtualenv
and virtualenvwrapper
):
python3 -m pip install virtualenv virtualenvwrapper
You will see a message of success shown after the installation.
In your .zshrc
file, include the following:
plugins=(
git
history-substring-search
virtualenvwrapper
)
# Add new Python version to PATH because we will be installing
# virtualenv related packages into its bin folder
export PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:$PATH"
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source virtualenvwrapper.sh
Restart your Terminal and you should be able to mkvirtualenv my_env
which will create a new virtual env using Python 3.x.
The oh-my-zsh plugin should activate (or workon
) the virtual env automatically upon entering a directory with the same name of the virtual env.
Note that for this plugin to work, the project directory must be a git repo, otherwise the env is ignored.