Ahmad Awais



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

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /opt/homebrew/opt/[email protected]/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/[email protected]/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 at Langbase.com Β· Ex VP DevRel Rapid Β· Google Developers Advisory Board (gDAB) founding member. πŸ§‘β€πŸ’» AI/ML/DevTools Angel Investor ❯ AI/ML Advisory Board member San Francisco, DevNetwork

🎩 Award-winning Open Source Engineer & Dev Advocate 🦊 Google Developers Expert Web DevRel πŸš€ NASA Mars Ingenuity Helicopter mission code contributor πŸ† 8th GitHub Stars Award recipient with 3x GitHub Stars Award (Listed as GitHub's #1 JavaScript trending developer).

🌳 Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator. πŸ“Ÿ Teaching thousands of developers Node.js CLI Automation (100 videos Β· 22 Projects) & VSCode.pro course. Over 142 Million views, 22 yrs Blogging, 56K developers learning, 200+ FOSS.

✌️ Author of various open-source dev-tools and software libraries utilized by millions of developers worldwide ⓦ WordPress Core Developer πŸ“£ TEDx Speaker with 100+ international talks.

✨ As quoted by: Satya Nadella Β· CEO of Microsoft β€” Awais is an awesome example for developers.
πŸ™Œ Leading developers and publishing technical content for over a decade πŸ’œ Loves his wife (Maedah) ❯ Read more about Ahmad Awais.

πŸ‘‹β€¦ Awais is mostly active on Twitter @MrAhmadAwais


Developers Takeaway

Stay ahead in the web dev community with Ahmad's expert insights on open-source, developer relations, dev-tools, and side-hustles. Insider-email-only-content. Don't miss out - subscirbe for a dose of professional advice and a dash of humor. No spam, pinky-promise!

✨ 172,438 Developers Already Subscribed
Comments 1