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
🌐
GitHub
github.com › orgs › Homebrew › discussions › 3696
Symlink not being created for my Python install · Homebrew · Discussion #3696
September 27, 2022 - /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/sirromey/opt/homebrew/opt/python@3.10/libexec/bin · looks wrong. It seems like the last entry should be ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... Ohh.. my bad. I add the ~ and it routed it to the user I think. It works fine now. Thanks a lot. If possible, it would be best if brew could do it automatically while installing.
Discussions

Python symlink shenananigans, guest starring pyEnv and Homebrew.
My advice is to never, ever, use the Hombrew Python for anything—that version of Python is strictly for other Homebrew formulae to use. The reason for this is that one day you’re going to run brew upgrade on some formula that depends on Python and if it upgrades Python in the process it will wreck your environment. So you should definitely use pyenv to manage your Python version but really you should avoid installing any Python packages there too. Why? Unlike some other programming languages you can only install ONE version of a package at a time. So if you have one project that needs sometool==1.0.0 and another project that needs sometool==2.0.0 you’re going to have problems. Instead, keep your pyenv environment as clean as possible and use a virtualized environment per project with Pipenv (my preference and maintained by the Python package authority) or Poetry (the community favorite). More on reddit.com
🌐 r/MacOS
3
9
May 12, 2022
How to symlink python in Homebrew? - Stack Overflow
Error: Could not symlink file: /usr/local/Cellar/python/2.7.3/bin/smtpd.py Target /usr/local/bin/smtpd2.py already exists. You may need to delete it. To force the link and delete this file, do: brew link --overwrite formula_name ... Sign up to request clarification or add additional context in comments. ... This worked for me to. Does this problem happen because of a prior python install... More on stackoverflow.com
🌐 stackoverflow.com
python formula does not link to /usr/local/bin/python
After a recent brew upgrade, the Python virtualenvwrapper.sh started giving errors. It said python cannot find virtualenvwrapper module. I was trying to fix this error message. Then I did a bit debugging and realized it started using the macOS system python (/usr/bin/python) after a while. No matter how many times I reinstalled python formula, I still did not get a /usr/local/bin/python symlink... More on github.com
🌐 github.com
5
July 30, 2017
Link multiple Python versions
When I run: brew install python@3.9 The default behavior should not be to install Python 3.10 and link all of the unversioned symlinks to the version of Python that I did not ask it to install. This breaks stuff, especially for dependencies that need to be installed via pip. More on github.com
🌐 github.com
7
1
🌐
Stack Overflow
stackoverflow.com › questions › 60711023 › after-installing-python3-with-homebrew-homebrew-doesnt-create-symlink-of-pytho
After installing python3 with Homebrew, Homebrew doesn't create symlink of python in /usr/bin/local - Stack Overflow
# Overwrite any python 3 brew symlink brew link --overwrite python3 # Link python3 to python2 using prior symlink to symlink ln -s /usr/local/bin/python3 /usr/local/bin/python
🌐
Reddit
reddit.com › r/macos › python symlink shenananigans, guest starring pyenv and homebrew.
r/MacOS on Reddit: Python symlink shenananigans, guest starring pyEnv and Homebrew.
May 12, 2022 -

I have very recently discovered pyEnv and used that to set my default python system install on Monterey 12.3.1 to the latest version of Python (3.10.4 as of yesterday). Installed and configured, and all is good.

Prior to discovering pyEnv, I have python installed via Homebrew.

The latest version of Python I can have installed via Homebrew ( brew upgrade python ) is 3.9.12 and I have many packages symlinked to this version. Removing this install of python ( brew uninstall --ignore-dependencies python ) breaks all of these packages, obviously.

Rather than having two distinct versions of Python installed, is there a reasonably simple way to divert all my Homebrew package symlinks to the 3.10.4 pyEnv environment so that I can then remove the 3.9.12 enviroment from Homebrew.

I'm not afraid of the command line, but symlinks hurt my brain. :) Would the 'brew link' command be my friend?

🌐
Readthedocs
python-guide-fil.readthedocs.io › en › latest › starting › install3 › osx.html
Installing Python 3 on Mac OS X — The Hitchhiker's Guide to Python
$ python --version Python 2.7.10 # Referencing OSX system install $ which python /usr/bin/python # Yup, homebrew's would be in /usr/local/bin # Symlink /usr/local/bin/python to python3 $ ln -s /usr/local/bin/python3 /usr/local/bin/python $ python --version Python 3.6.4 # Success!
🌐
Michael Currin
michaelcurrin.github.io › dev-cheatsheets › cheatsheets › python › install › install-and-upgrade.html
Install and upgrade Python | Dev Cheatsheets
$ brew link python@3.9 --force Linking /usr/local/Cellar/python@3.9/3.9.0... 21 symlinks created 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
🌐
Codetinkering
codetinkering.com › homebrew-python-not-found
Homebrew Python Not Found – Code Tinkering
When you install Python using Homebrew, ... pip3 work but python and pip will not! First create and copy the symlink location by running the following: brew link python ·...
Find elsewhere
🌐
GitHub
github.com › Homebrew › homebrew-core › issues › 16212
python formula does not link to /usr/local/bin/python · Issue #16212 · Homebrew/homebrew-core
July 30, 2017 - $ brew unlink python && brew link python -v Unlinking /usr/local/Cellar/python/2.7.13_1... 32 symlinks removed Linking /usr/local/Cellar/python/2.7.13_1... ln -s ../Cellar/python/2.7.13_1/bin/2to3-2 2to3-2 ln -s ../Cellar/python/2.7.13_1/bin/2to3-2.7 2to3-2.7 ln -s ../Cellar/python/2.7.13_1/bin/easy_install easy_install ln -s ../Cellar/python/2.7.13_1/bin/easy_install-2.7 easy_install-2.7 ln -s ../Cellar/python/2.7.13_1/bin/idle2 idle2 ln -s ../Cellar/python/2.7.13_1/bin/idle2.7 idle2.7 ln -s ../Cellar/python/2.7.13_1/bin/pip pip ln -s ../Cellar/python/2.7.13_1/bin/pip2 pip2 ln -s ../Cellar/py
Author: Homebrew
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 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).

🌐
GitHub
github.com › Homebrew › discussions › discussions › 3696
Symlink not being created for my Python install · Discussion #3696 · Homebrew/discussions
September 27, 2022 - /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/sirromey/opt/homebrew/opt/python@3.10/libexec/bin · looks wrong. It seems like the last entry should be ... Beta Was this translation helpful? Give feedback. ... Something went wrong. ... Ohh.. my bad. I add the ~ and it routed it to the user I think. It works fine now. Thanks a lot. If possible, it would be best if brew could do it automatically while installing.
Author: Homebrew
🌐
GitHub
github.com › Homebrew › homebrew-core › issues › 27140
Python3: Unversioned symlinks are installed to directory not in PATH · Issue #27140 · Homebrew/homebrew-core
April 26, 2018 - if brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue? ... What happened (include command output) Installed but links python → python3, pip → pip3 etc.
Author: Homebrew
Top answer
1 of 3
56

I presume you mean that you want the command python to start the Python3 interpreter, and pip to start pip3.

The clue is in the message:

Unversioned symlinks python, python-config, pip etc. pointing to python3, python3-config, pip3 etc., respectively, have been installed into /usr/local/opt/python/libexec/bin

That means... "if you want the command python to start python3 and pip to start pip3, you need to put /usr/local/opt/python/libexec/bin at the start of your PATH."

So, in your login script ($HOME/.profile or similar), you need to put:

export PATH=/usr/local/opt/python/libexec/bin:$PATH

Then log out and log back in for it to take effect.


As an aside, brew link python3 only means... "create a symbolic link in /usr/local/bin/python3 that points to /usr/local/Cellar/python/3.7.0/python3".

You can see that link, and where it points to, with:

ls -l /usr/local/bin/python3
2 of 3
5

I had installed python via brew and had to follow different steps:

brew install python

Later, I needed the path to add to my $PATH as export PATH=/usr/local/opt/python/libexec/bin:$PATH wasn't working for me.

I ran:

brew info python

Got this:

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

And then added this to my .zshrc file

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

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.

For more details, I shared the entire process in Python not found on MacOS. I hope this helps.

Make sure to reload your terminal, a fancy way to do that is by running:

exec $SHELL -l
🌐
Reddit
reddit.com › r/learnpython › error installing python3 on mac
r/learnpython on Reddit: Error Installing Python3 on Mac
April 26, 2019 -

Hi all,

I'm trying to install python3 on a Mac running macOS Mojave but am running into trouble. First, I updated homebrew and ran the command xcode-select --install. Then, I ran the command brew install python3. Now, I get this error.

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.3.mojave.bottle.
==> Downloading from https://akamai.bintray.com/25/25e0099852136c4ef1efd221247d0
######################################################################## 100.0%
==> Pouring python-3.7.3.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
  brew link --overwrite python

To list all files that would be deleted:
  brew link --overwrite --dry-run python

Possible conflicting files are:
/usr/local/bin/2to3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/2to3
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> /usr/local/Cellar/python/3.7.3/bin/python3 -s setup.py --no-user-cfg install
==> Caveats
Python has been installed as
  /usr/local/bin/python3

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

If you need Homebrew's Python 2.7 run
  brew install python@2

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺  /usr/local/Cellar/python/3.7.3: 3,863 files, 59.8MB

So now when I run the command python3 --version, it says the command can't be found. I'm a bit new to mac software as I'm a predominant Windows user so I'm a bit puzzled. What's going on?

🌐
GitHub
github.com › Homebrew › homebrew-core › issues › 24792
installing python3 symlinked incompatible "python" binary · Issue #24792 · Homebrew/homebrew-core
March 3, 2018 - Homebrew then created a python ... to symlink, or it installs the conflicting packages under a different name. ... $ brew install llvm ......
Author: Homebrew
🌐
Stack Overflow
stackoverflow.com › questions › 73522011 › brew-symbolic-linking-for-python-is-not-working-what-can-i-do
macos - Brew symbolic linking for Python is not working. What can I do? - Stack Overflow
The table of symbolic links for my terminal session was not updated yet. Therefore, it was stuck giving me the wrong symlink. The rehash command fixed it. ... Sign up to request clarification or add additional context in comments. ... rehash isn't installed by default on later OS versions.
🌐
Mac Install Guide
mac.install.guide › python › brew
Brew Install Python · Mac Install Guide
February 25, 2024 - . . ==> Caveats ==> python@3.15 ...hon@3.15/libexec/bin `idle3.15` requires tkinter, which is available separately: brew install python-tk@3.15 `dbm.gnu` is available separately: brew install python-gdbm@3.15 For more information ...
🌐
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 - Once installed, you can verify the new Python 3.12 version: ... 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]