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
macos - Switching Python version installed by Homebrew - Stack Overflow
Linking a python3 version unlinks all other python3 versions.
Link multiple Python versions
python - brew install doesn't link python3 - Stack Overflow
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).
There is an Homebrew known issue related to side by side install of Python 3.8 / 3.9. To workaround, following commands should work for you:
brew unlink python@3.9
brew unlink python@3.8
brew link --force python@3.9
Re-opening your terminal or execute command rehash can be required to take account the change.
Use pyenv. It's a software that lets you switch between any and all Python versions installed on your system. To install pyenv, use the following code in the command-line:
curl https://pyenv.run | bash
exec $SHELL
Then find the name of the python version you want to switch to with this:
pyenv versions
And select it with this:
pyenv global <version-name>
In your case, it's most likely named 3.9.0.
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
So I installed python 3.14 via Homebrew on my Mac, but when I check what version python is running it points to 3.13. What do I need to do to fix this? I tried looking it up on Google but I got varying answers and I don't want to screw things up on my computer.
Any help would be greatly appreciated.
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)
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.
The issue seems to be in the difference between python@3.11 and python@3.12 Homebrew Ruby scripts.
3.11 has link_overwrite for python3 which sets a bunch of symlinks in /usr/local/bin/ (which is usually in your $PATH) to use 3.11.
3.12 lacks this and so your shell is not seeing them.
You can rectify this either by modifying your $PATH as in the other reply, or replacing the symlink manually:
cd /usr/local/bin && rm python3 && ln -s ../Cellar/python@3.12/3.12.1/bin/python3.12 python3
Edit 2024-02-25: About four days ago, the below PR was merged. I believe brew install python should now install Python 3.12.
python3 in Homebrew won't point at 3.12 until this PR is merged. AFAIK Homebrew don't switch the default python3 to the latest version until all the Python software that Homebrew packages are confirmed to work with the new version.
If you really need python3 to point at 3.12 globally right now, I personally like @Iskander14yo's suggestion to use pyenv (above).