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 OverflowAfter 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
Python symlink shenananigans, guest starring pyEnv and Homebrew.
How to symlink python in Homebrew? - Stack Overflow
python formula does not link to /usr/local/bin/python
Link multiple Python versions
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?
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).
The error means those files already exist in /usr/local/bin
If you 'ls -lF' on that dir, are they sym links that point to a path with the word 'cellar' in it?
If so, then brew already put them in place for you. You're probably missing /usr/local/bin from your PATH
If not, then something else put them there earlier. On a fresh mac, that directory is empty. Brew is a better way to manage those files, so if it was my machine I would remove those files from /usr/local/bin, then you can run brew link. I'd probably keep them in another spot temporarily in case I later discovered a need for them.
Also, run brew doctor when you have a chance. It will tell you about any other problems like this.
Brew wants to own /usr/local/bin. I would let it, it's a great tool.
Fix for macOS Mojave 10.14.2 (2018-12)
I was able to install python with brew using these commands.
brew install python
sudo chown -R $(whoami) $(brew --prefix)/*
sudo install -d -o $(whoami) -g admin /usr/local/Frameworks
brew link python
python3 --version
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,pipetc. pointing topython3,python3-config,pip3etc., 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
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
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?