Setup Python 3 on Latest macOS

Matt Wang
2 min readJan 6, 2023

--

The default Python version on macOS (the latest macOS version while writing is Ventura 13.1) is 2. However, Python 3 is also on the system.

To run Python 3, typing the following command in a terminal window:

python3

However, it is not recommended. A better solution is using Python virtual environment.

Step 1 Install virtualenv

# Install virtualenv
pip3 install virtualenv
# Add the path of Python executable files to $PATH variables
echo 'export PATH="$HOME/Library/Python/3.8/bin:$PATH"' >> ~/.zshrc
# Make the settings effective
source ~/.zshrc

Step 2 Create Python virtual environment

# Create a Python virtual environment named .p3
virtualenv -p python3 ~/.p3
# Make zsh to load the virtual environment automatically
echo 'source ~/.p3/bin/activate' >> ~/.zshrc

Step 3 Load virtualenv in current terminal

source ~/.zshrc

Step 4 Test

python --version
# Output
# Python 3.x.x

Why use virtual environment

  1. You will not mess up the system, the changes you made only apply on the virtual environment. If you ruin your virtual environment, simply remove it and recreate a new one
  2. You may have multiple virtual environments. For example, you may have some old applications or libraries depending on Python 2, and some of others rely on Python 3. You can create two environments to satisfy all of them
  3. You may have two same environments with different versions of a same library for testing to find out which one performs better. As the environment is completely independent of others, the tests do not intrude on each other.
  4. You may have a development and production environments that each of them has different settings
  5. And so on

--

--

Matt Wang

Empowering others through handy and innovative tech solutions and sharing knowledge. Stay tuned with my new articles.