As suggested by the Homebrew (executable brew) installer itself, be sure to add this to your .bashrc file or .zshrc file:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
Answer from Pamput on Stack OverflowAs suggested by the Homebrew (executable brew) installer itself, be sure to add this to your .bashrc file or .zshrc file:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
For Apple silicon machines, the paths are slightly different. After running brew install python, you must ensure your ~/.zshrc file uses the correct Homebrew paths:
# Homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"
# Homebrew: Python
export PATH="/opt/homebrew/opt/python/libexec/bin:$PATH"
Results:
% which python
/opt/homebrew/opt/python/libexec/bin/python
% python --version
Python 3.9.9
% which pip
/opt/homebrew/opt/python/libexec/bin/pip
% pip -V
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
Brew's Python interpreter changed its location again and I had to update my ~/.zshrc file to:
export PATH="$(brew --prefix)/opt/python@3/libexec/bin:$PATH"
There isn't a .../opt/python/... anymore which is annoying, because now I have to specify v3 explicitly, but at least better than having to specify the minor version like in the comments.
Fresh Apple M1 install of homebrew and python, need to update path?
Installed Homebrew in Terminal (OSX 10.11.4), confused on how to "insert the Homebrew directory at the top of your PATH environment variable."
How to add Python@3.11 to Path
homebrew - How to make python 3.11 my default python3 with brew - Ask Different
Hey LearnPython,
I'm jumping into Python and I've been working through all the introductions, playing the games, reading tutorials, and now I want to start playing with it on my desktop.
So I started the process of ensuring everything I'm using is up to date following the [Hitchhiker's Guide to Python] (http://docs.python-guide.org/en/latest/starting/install/osx/#install-osx). My Mac already has Python installed, but it's older. I entered the Homebrew install script in my terminal and then I reached the part in the instructions where it says and I'm not sure what it means or how to make sure that I've installed it at the top of my PATH environment variable:
"The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file
Then it shows this a little below the piece mentioned above:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
I've been searching all over and I've found questions similar to mine, but not worded the same or geared for a different program. I'm very new to all of this and want to make sure I'm doing it properly.
Thank you!
Note: This applies to any versioned Python installation with Homebrew
After installing Python 3.11, you are given the location of the bin folder with Python 3.11:
==> Caveats
Python has been installed as
/usr/local/bin/python3.11
Unversioned and major-versioned symlinks `python`, `python3`, `python-config`, `python3-config`, `pip`, `pip3`, etc. pointing to
`python3.11`, `python3.11-config`, `pip3.11` etc., respectively, have been installed into
/usr/local/opt/[email protected]/libexec/bin
You can add this folder to be first in your PATH and python or python3 will pick up Python 3.11 (since those are in the folder):
So: add the following line to ~/.zshrc:
export PATH="$(brew --prefix)/opt/[email protected]/libexec/bin:$PATH"
brew --prefix ensures that the correct path is used, regardless of where your brew install resides.
On macOS Ventura & Sonoma on Apple Silicon
To install homebrew's version of python3:
brew install python3
This installs brew's version of python3.x but does not override the the link to macOS's version of python3 when you use the python3 command. You can confirm which python3 is being used with the which python3 command. Now, you have two primary options here:
- You can unlink the system default's python3 and relink python3 to the homebrew version (see kraspa11's answer)
- You can simply add an alias for python3 in your
~/.zshrcfile which can point to brew's version instead (I prefer this because it results in fewer edits to system defaults).
If you prefer option #2:
Open up ~/.zshrc with nano ~/.zshrc or your desired editor. BTW, if you want to see "hidden" files/folders in your /Users/[username] folder where .zshrc resides, open your user folder in finder and press ⇧ Shift + ⌘ Command + . (period). This will show/hide all hidden files and folders in your Finder.
At the end of the .zshrc file, add the following lines:
# ensure "python3" command uses homebrew's version of python3
alias python3=/opt/homebrew/bin/python3
# OPTIONAL: ensure "python" command uses homebrew's version of python3
alias python=/opt/homebrew/bin/python3
I use /opt/homebrew/bin/python3 instead of /opt/homebrew/opt/[email protected] so if/when you update your version from 3.11 to 3.12 and so on, your aliases should always work (until version 4).
Now, save and close your edited .zshrc file. To refresh your terminal to use the new alias(es), enter:
source ~/.zshrc
To ensure that your commands are pointing to the brew version of python3:
which python3 should respond: python3: aliased to /opt/homebrew/bin/python3
and
which python should respond: python: aliased to /opt/homebrew/bin/python3
NOTE: I have only tested all of the above on Apple silicon macOS Sonoma (which is in developer beta, but should be functionally the same as Ventura).
I moved from Windows to a MacBook yesterday (runs MacOS 14 Sonoma on Apple Silicon). I'm trying to get Python to work properly on my MacBook but I'm having a hard time figuring it out.
I'm being able to run Python from the terminal but it doesn't run from VSCode. From the terminal (ZSH) too, only python3 ran but not python. To get around that, I followed an online article and added a ~/.zshrc file. I added these two lines to it:
alias python="/usr/bin/env python3" alias pip="/usr/bin/env pip3"
I tried to install a Python package using pip but it hit me with a WARNING: The script normalizer is installed in '/Users/my_username/Library/Python/3.9/bin' which is not on PATH.
So till now I've understood that Python can be installed on Mac in 3 ways:
-
The default inbuilt Python that comes with Mac out of the box.
-
Python installed from the Python website via an installer.
-
Python installed via Homebrew.
I am not being able to figure out the paths where each of these methods install Python. Which method is better for installing? Homebrew or download from the website? And once I have Python using one of the options, how do I make sure that it is the one used over the system Python? If I override the system Python, will there be any issues? How do I get Python to run from VSCode?
My MacOS and command line knowledge is very rudimentary so please correct me if I've said something wrong.
You should edit ~/.bash_profile (create the file if it does not exist) to set the PYTHONPATH environment variable:
export PYTHONPATH=`brew --prefix`/lib/python2.7/site-packages:$PYTHONPATH
Since you installed PyQt by using Homebrew, you should also use Homebrew Python 2.
To install it, run: brew install python
Now, you can import PyQt normally.