Ahmad Awais

NAVIGATE


SHARE


Python not found on MacOS | Install Python with brew | Fix $PATH

Ahmad AwaisAhmad Awais

Hence, in June 2019, Apple announced it was deprecating the Python 2.7 programming language, and in April 2022, they removed support for Python 2.7 on macOS devices running Monterey 12.3 and above.

Now if you were to install the latest macOS, open the terminal to run

python --version

You will get this response:

command not found: python

Not ideal, I know.

Step 1: Install Python via brew#

Pre-requisite: Make sure brew is installed.

Advanced users: You can use pyenv, to manage different versions, I don’t want an additional delay on the terminal due to it, so I don’t use it.

brew install python

This will install the latest version of Python. Only you can access it via python3 and pip via pip3 — not ideal.

To fix this, run this:

brew info python

It should give you the following info:

Python has been installed as
  /opt/homebrew/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /opt/homebrew/opt/python@3.11/libexec/bin

Based on this info, Python 3.11 is installed on your Mac using Homebrew, and the unversioned symlinks have been set up.

Let’s make Python 3.11 the default version.

Step 2: Open bash or zsh config#

Open the shell profile file in your preferred text editor. For example, you can use the nano editor with the following command:

nano ~/.bash_profile

I use zsh and VS Code, so I ran this:

code ~/.zshrc

Step 3: Add Python to your $PATH#

Add the following lines to the file:

export PATH="/opt/homebrew/opt/python@3.11/libexec/bin:$PATH"

We got this from the brew info python output. Told ya, that’s useful.

Step 4: Save, and you’re done!#

Save the changes to the file by pressing Control + O, then press Enter. Exit the editor by pressing Control + X.

For me, I just saved it via VS Code. No biggie.

Now reload the shell profile by running the following command:

source ~/.bash_profile

For zsh, you could use this:

source ~/.zshrc

I prefer another approach and have it aliased as reload alias reload="exec $SHELL -l" — you don’t have to use it.

The command exec $SHELL -l is used to start a new login shell. Here’s what each part of the command does:

By running exec $SHELL -l, you are essentially starting a new login shell, which will execute the login shell initialization scripts and set up the environment variables as defined by your system and user settings.

This can be useful if you have made changes to your shell configuration files and want to apply those changes immediately without having to log out and log back in.

## Now you got python and pip Yay!!

Verify that Python 3.11 is now the default version by running the following command:

python --version

It should display the version number of Python 3.11.

With these steps, you have made Python 3.11 the default version on your Mac. You can now use python to refer to Python 3.11 in your terminal.

 

Founder & CEO of ⌘ Command Code, the most used coding agent for open models: 160K+ users, 50K+ paying customers. Founded Langbase (AI cloud for agents with memory & tools).

"What an awesome example for developers." — Satya Nadella, CEO of Microsoft, on my NASA Ingenuity code.

NASA Ingenuity Mars Helicopter code contributor · 6× GitHub Star, one of the first 8 Gold Stars · #1 trending JavaScript developer on GitHub · 6× Google Developer Expert · 6× Microsoft MVP.

Ex VP DevRel & DevTools at RapidAPI · Google Developers Advisory Board (gDAB) founding member · OpenAPI Business Governing Board, Linux Foundation · SF DevNetwork AI/ML Advisory Board · Angel investor (Replit, Resend, Daytona, Gumroad and you?).

Award-winning open source engineering leader: 300+ projects, 50–100M downloads a year, including Shades of Purple (5M+ developers) and corona-cli (10B+ queries).

Taught 217K+ developers via NodeCLI.com and VSCode.pro. 160+ talks. Blogging since 2000, billions of views.

❯ Read more about Ahmad Awais or come say hi on 𝕏 @MrAhmadAwais.

Newsletter

The Developer Takeaway

Founder notes on AI, dev tools, and building developer products. No spam.

247,813+ developers subscribed
Comments 2