brew install python or brew info python output mentions:
Unversioned symlinks
python,python-config,pipetc. pointing topython3,python3-config,pip3etc., respectively, have been installed into /opt/homebrew/opt/[email protected]/libexec/bin
So running, as root (for Bash (executable bash), use the ~/.bash_profile file):
echo 'export PATH=/opt/homebrew/opt/[email protected]/libexec/bin:$PATH' >> ~/.zprofile
source ~/.zprofile
gets you those symlinks created by Homebrew, python=python3, pip=pip3, etc.
python --version
Output:
Python 3.9.10
And:
pip --version
Output:
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
Answer from Callum M on Stack OverflowWhat are your thoughts on Homebrew for getting Python3 up and running on a Mac? And what is your preferred method on your machine?
How to make macOS use the Python interpreter installed by Homebrew - Stack Overflow
homebrew - How to install Python packages for brew installed Pythons? - Stack Overflow
macos - How to link home brew python version and set it as default - Stack Overflow
So far, I've worked with conda environments, installing python3 directly from the exe on the site, and homebrew. I feel like every time I use homebrew on a new computer there are SO MANY MORE PROBLEMS that I run into. Pip install fails on really simple things, brew cleanup never works, it's so frustrating...
What is the simplest way you've found to get Python3 up and running on a mac?
brew install python or brew info python output mentions:
Unversioned symlinks
python,python-config,pipetc. pointing topython3,python3-config,pip3etc., respectively, have been installed into /opt/homebrew/opt/[email protected]/libexec/bin
So running, as root (for Bash (executable bash), use the ~/.bash_profile file):
echo 'export PATH=/opt/homebrew/opt/[email protected]/libexec/bin:$PATH' >> ~/.zprofile
source ~/.zprofile
gets you those symlinks created by Homebrew, python=python3, pip=pip3, etc.
python --version
Output:
Python 3.9.10
And:
pip --version
Output:
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
If you want to install Python 3 using Homebrew:
brew install python3
Output:
==> Downloading http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/python3-3.3.0.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python3/3.3.0 --enable-ipv6 --datarootdir=/usr/local/Cell
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0/share/python3
==> Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
Already downloaded: /Library/Caches/Homebrew/distribute-0.6.35.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Downloading https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/pip-1.3.1.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Caveats
Homebrew's Python3 framework
/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework
Distribute and Pip have been installed. To update them
pip3 install --upgrade distribute
pip3 install --upgrade pip
To symlink "Idle 3" and the "Python Launcher 3" to ~/Applications
`brew linkapps`
You can install Python packages with
`pip3 install <your_favorite_package>`
They will install into the site-package directory
/usr/local/lib/python3.3/site-packages
Executable python scripts will be put in:
/usr/local/share/python3
so you may want to put "/usr/local/share/python3" in your PATH, too.
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
Once installed update your system PATH variable, add the next line to the ~/.bash_profile file:
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
And then:
source ~/.bash_profile
Now launch Python:
python3
Output:
Python 3.3.0 (default, Mar 26 2013, 10:01:40)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
You can check the python3 path:
which python3
Output:
/usr/local/bin/python3
Use pip3. The "caveats" text you see when you run brew info python3 was printed for you after python3 was installed; that text is frequently helpful! It reads:
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.4/site-packages
How to install Python packages for brew installed Pythons?
Some Python packages can be installed via Brew, e.g.:
brew install python-setuptools
After installing python3 with brew install python3
I was getting the error:
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
After typing brew link python3 the error was:
Linking /usr/local/Cellar/python/3.6.4_3... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
To solve the problem:
sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/*
brew link python3
After this, I could open python3 by typing python3 👍
(From https://github.com/Homebrew/homebrew-core/issues/20985)
In the Terminal, type:
brew link python
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"
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.