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)

Answer from lenooh on Stack Overflow
Discussions

Link multiple Python versions
But it made me think about the possibility of using brew link --force --overwrite to achieve my goal, albeit with the downsides I theorized about. All is well. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... The python makefile support the altinstall target, that create just binaries with the full version ... More on github.com
🌐 github.com
7
1
homebrew - How to install specific version of python on OS X - Ask Different
So. if you want to install a specific version then, you must check before install. ... Find the version you want. Now you can use brew install with the corresponding commit hash: 3.4.3_2: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/bd43f59bd50bb49242259f327cb6ac7a8dd59478/Formula/python3... More on apple.stackexchange.com
🌐 apple.stackexchange.com
May 6, 2016
Specific python version
So, the question is, do I have to link manually via ln -s python3.10 python3, and can Homebrew still do that for me? Is there some way to tell Homebrew that I'm only using python3.10, and not python3.11? For example, set the environment variable HOMEBREW_PYTHON_VERSION=3.10. And then, all subsequent brew python will be specific ... More on github.com
🌐 github.com
1
1
February 27, 2023
Python Version help on Mac
Have you looked at virtual environments? I've been using direnv (installed with Homebrew) to set the Python version for a particular project folder. You can make a .envrc file containing layout /path/to/specific/python when you have multiple versions kicking around. Then when you cd into that folder, it should load the one you chose. And any extra packages you install with pip or whatever should only apply to that folder also. More on reddit.com
🌐 r/learnpython
36
111
March 26, 2021
Top answer
1 of 3
40

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.

2 of 3
18

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:

  1. You can unlink the system default's python3 and relink python3 to the homebrew version (see kraspa11's answer)
  2. You can simply add an alias for python3 in your ~/.zshrc file 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).

🌐
AskPython
askpython.com › python › examples › set-homebrew-default-python-version-macos
How to Link and Set Homebrew Python 3.12 as the Default Python Version on macOS - AskPython
February 28, 2024 - We need to explicitly link Python 3.12 as the default python executable. Homebrew maintains symlinks in /usr/local/bin to manage version defaults for various tools and languages. To set Python 3.12 as the new default executable for the python command, run: brew unlink [email protected] && brew link --force --overwrite [email protected]
Top answer
1 of 1
1

It's not currently possible, but I believe it is possible in principle if the various Python formulae were fixed up to support this.

Dealing with the various executables (python3, pip3, etc) is fairly straightforward, but there are some conflicts that will require a bit more work:

❯ brew link --force --dry-run --overwrite python@3.10
Would remove:
/usr/local/bin/2to3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/2to3
/usr/local/bin/idle3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/idle3
/usr/local/bin/pip3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pip3
/usr/local/bin/pydoc3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pydoc3
/usr/local/bin/python3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3
/usr/local/bin/python3-config -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3-config
/usr/local/bin/wheel3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/wheel3
/usr/local/share/man/man1/python3.1 -> /usr/local/Cellar/python@3.9/3.9.9/share/man/man1/python3.1
/usr/local/lib/pkgconfig/python3-embed.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3-embed.pc
/usr/local/lib/pkgconfig/python3.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3.pc
/usr/local/Frameworks/Python.framework/Headers -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Headers
/usr/local/Frameworks/Python.framework/Python -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Python
/usr/local/Frameworks/Python.framework/Resources -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Resources
/usr/local/Frameworks/Python.framework/Versions/Current -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/Current

This might require special handling of the contents of *.framework directories in brew.

Top answer
1 of 6
16

I have done this sort of thing in two ways - however both do not coexist with homebrew although I suspect there should be a way similar to the macports one.

General package manager

The first is using Macports as the package manager. There are separate ports for several python versions 2.x and 3.x currently 2.4, 2.5, 2.6, 2.7 and 3.1, 3.2, 3.3 3.4 and 3.5. For example to install 3.4 do sudo port install python34 There is also a python_select port that running it allows you to choose which version of python is run by /opt/bin/python. e,g, to select macports python 2.7 port select --set python python27

Each package manager needs to run as the only package manager otherwise it will be confused with unexpected different versions of libraries and executables on its paths.

From comments the similar homebrew way is given in https://stackoverflow.com/a/4158763/151019 Short answer seems to be brew switch the equivalent to port_select

Python version managers

The other way is install direct from python.org This will install a python into /usr/local/bin I think this installs a python and python3 executable. The issue with Homebrew is that it assumes that things in /usr/local are installed by it and so brew doctor will report these python.org pythons and libraries as issues and as this question shows also the frameworks in /Library will be problematic.

EDIT 8/2018 *** I would now suggest using conda either miniconda or anaconda. This is another package manager but based and mainly meant for python, it also gives the equivalent of python's virtual environments and pyenv (as per other answer) and so each project can be in a different python and different libraries (Macports only switches python version for all projects)

2 of 6
115

For Python in macOS, use pyenv:

brew install pyenv

To install a specific Python version, run:

pyenv install <version>

To select a version for every command run with the current folder:

pyenv local 3.5.0

Note that you must update PATH in your environment to find pyenv's python3 before any other:

PATH="~/.pyenv/shims:${PATH}"

With recent version of OSX(13.X) the path is moved to /etc/paths.d/ Add a file eg: pyenvpath to /etc/paths.d/pyenvpath Add the path to that file.

To list available versions:

pyenv versions

See https://gist.github.com/Bouke/11261620 for more information.

🌐
Opensource.com
opensource.com › article › 19 › 5 › python-3-default-mac
The right and wrong way to set Python 3 as default on a Mac | Opensource.com
# If you need Homebrew's Python 2.7 run $ brew install python@2 · At any time, we can remove the aliases from our shell's configuration file to go back to using the default copy of Python on the system. The pip command is the default package manager specifically for Python packages. Although we changed our default Python command to be version 3, we have to alias our pip command separately if it's on the previous version.
Find elsewhere
🌐
Mac Install Guide
mac.install.guide › python › brew
Brew Install Python · Mac Install Guide
February 25, 2024 - For example, Python 3.15 may be the newest version installed by Homebrew but you need to work on an application that requires Python 3.7. You can use brew search python to see if an earlier Python version is available.
Top answer
1 of 1
1

It's not currently possible, but I believe it is possible in principle if the various Python formulae were fixed up to support this.

Dealing with the various executables (python3, pip3, etc) is fairly straightforward, but there are some conflicts that will require a bit more work:

❯ brew link --force --dry-run --overwrite python@3.10
Would remove:
/usr/local/bin/2to3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/2to3
/usr/local/bin/idle3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/idle3
/usr/local/bin/pip3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pip3
/usr/local/bin/pydoc3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pydoc3
/usr/local/bin/python3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3
/usr/local/bin/python3-config -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3-config
/usr/local/bin/wheel3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/wheel3
/usr/local/share/man/man1/python3.1 -> /usr/local/Cellar/python@3.9/3.9.9/share/man/man1/python3.1
/usr/local/lib/pkgconfig/python3-embed.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3-embed.pc
/usr/local/lib/pkgconfig/python3.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3.pc
/usr/local/Frameworks/Python.framework/Headers -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Headers
/usr/local/Frameworks/Python.framework/Python -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Python
/usr/local/Frameworks/Python.framework/Resources -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Resources
/usr/local/Frameworks/Python.framework/Versions/Current -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/Current

This might require special handling of the contents of *.framework directories in brew.

🌐
Homebrew
formulae.brew.sh › formula › python@3.12
Homebrew Formulae: python@3.12
brew install python@3.12 · Interpreted, interactive, object-oriented programming language · https://www.python.org/ License: Python-2.0 · Development: Pull requests · Formula JSON API: /api/formula/python@3.12.json · Formula code: ...
🌐
Homebrew
docs.brew.sh › Language-Runtimes-and-Packages
Homebrew Documentation: Language Runtimes and Packages
Homebrew provides supported Python 3 releases and does not provide Python 2. The python and python3 aliases select Homebrew’s current default Python formula. Versioned formulae for supported older releases remain available according to the versioned formula policy.
🌐
GitHub
github.com › orgs › Homebrew › discussions › 5014
Is It Possible to Install Python 3.11.3 in Particular with Homebrew? · Homebrew · Discussion #5014
December 31, 2023 - ==> Formulae python@3.11 ✔ python@3.10 ✔ python@3.12 ✔ To install python@3.11 ✔, run: brew install python@3.11 ✔ hubert@Huberts-Mac-Mini ~ % As Warning: No available formula with the name "python@3.11.3" suggests, Python 3.11.3 is not available as a formula through Homebrew. The above seems to be the case because when you look at the versions of Python available here:
🌐
Code2care
code2care.org › home › python › how to install python specific version (3.8, 3.9 or 3.10) using brew
How to install Python Specific version (3.8, 3.9 or 3.10) using Brew | Code2care
January 26, 2026 - If you want to install a specific version of Python using brew you can use brew install python followed by a @ (at sign) and the version number,
🌐
Homebrew
formulae.brew.sh › formula › python@3.14
Homebrew Formulae: python@3.14
brew install python@3.14 · Interpreted, interactive, object-oriented programming language · https://www.python.org/ License: Python-2.0 · Development: Pull requests · Formula JSON API: /api/formula/python@3.14.json · Formula code: ...
🌐
Michael Currin
michaelcurrin.github.io › dev-cheatsheets › cheatsheets › python › install › install-and-upgrade.html
Install and upgrade Python | Dev Cheatsheets
$ brew unlink python $ brew link python@3.9 Warning: python@3.9 is keg-only and must be linked with --force If you need to have this software first in your PATH instead consider running: echo 'export PATH="/usr/local/opt/python@3.9/bin:$PATH"' >> ~/.zshrc
🌐
DEV Community
dev.to › malwarebo › how-to-set-python3-as-a-default-python-version-on-mac-4jjf
Change Python Version Mac: How to set Python3 as a default python version on MacOS? - DEV Community
June 10, 2020 - Change the default python symlink to the version you want to use from above. Note that, we only need to choose the one that end with python3.*. Please avoid using the ones' that end with config or python3.*m or python3.*m-config. ... Close the current terminal session or keep it that way and instead open a new terminal window (not tab). Run this: ... Hah! That's it. Happy coding!! ... Worked! Thanks! I'm not saying anyone would want to install Python 3 without brew, but if they did, pip3 gets installed: $ pip3 --version pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8) $ pip3 install --upgrade pip Collecting pip Downloading files.pythonhosted.org/packages/54...