76

I just switched from MacPorts to HomeBrew. After installing all the required XCode versions and other software I tried installing python using homebrew: I think it successfully installed, but when I do which python it still shows me 2.7.3 which I think is the version shipped with Mountain Lion.

which python /usr/local/bin/python python --version Python 2.7.3 

so I tried to install again

brew install python --framework --universal Warning: python-2.7.5 already installed, it's just not linked 

But it says python 2.7.5 already install and not linked, I tried to do brew link python

That led me to following message so, I have no idea what I should be doing:

Linking /usr/local/Cellar/python/2.7.5... Warning: Could not link python. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/python/2.7.5/bin/smtpd2.py Target /usr/local/bin/smtpd2.py already exists. You may need to delete it. To force the link and overwrite all other conflicting files, do: brew link --overwrite formula_name To list all files that would be deleted: brew link --overwrite --dry-run formula_name 
2
  • 1
    Probable duplicate of several others. This one seems to have the best solution. Or maybe this one. Commented Oct 13, 2013 at 4:55
  • OK, and what happens when you execute those commands? Commented Oct 28, 2013 at 16:42

12 Answers 12

63

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)

Sign up to request clarification or add additional context in comments.

2 Comments

you don't have to chown -R /usr/local, fyi... posting answer below
Chaim Eliyah: probably. But, the code snippet is from the official homebrew repository.
15

In the Terminal, type:

brew link python 

2 Comments

nope, I get Linking /usr/local/Cellar/python/3.6.4_4... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks/Python.framework
brew link --overwrite [email protected] did the trick for me
13

For those looking for a version re-link using brew, I've found this command useful:

brew unlink [email protected] && brew link [email protected] 

It is possible that some errors appear, like:

Error: Could not symlink bin/pip3 Target /usr/local/bin/pip3 already exists. You may want to remove it: rm '/usr/local/bin/pip3' To force the link and overwrite all conflicting files: brew link --overwrite [email protected] To list all files that would be deleted: brew link --overwrite --dry-run [email protected] 

So following brew advice and running:

rm '/usr/local/bin/pip3' brew link --overwrite [email protected] 

Just worked for me. To check if symlinks are ok, run: ls -l /usr/local/bin/python*, you should see something like:

/usr/local/bin/python3 -> ../Cellar/[email protected]/3.10.2/bin/python3 /usr/local/bin/python3-config -> ../Cellar/[email protected]/3.10.2/bin/python3-config /usr/local/bin/python3.10 -> ../Cellar/[email protected]/3.10.2/bin/python3.10 /usr/local/bin/python3.10-config -> ../Cellar/[email protected]/3.10.2/bin/python3.10-config 

1 Comment

With [email protected] (3.9.18) brew fails to create the links for /usr/local/bin/python3, /usr/local/bin/python3-config and /usr/local/bin/pip3 which is inconvenient, and inconsistent at the very least.
12

If you used

brew install python 

before 'unlink' you got

brew info python /usr/local/Cellar/python/2.7.11 python -V Python 2.7.10 

so do

brew unlink python && brew link python 

and open a new terminal shell

python -V Python 2.7.11 

1 Comment

Like @eric-guo wrote: you need --force, so brew unlink python && brew link python2 --force.
7

I think you have to be precise with which version you want to link with the command brew link python like:

brew link python 3 

It will give you an error like that:

Linking /usr/local/Cellar/python3/3.5.2... Error: Could not symlink bin/2to3-3.5 Target /usr/local/bin/2to3-3.5 already exists. 

You may want to remove it:

rm '/usr/local/bin/2to3-3.5' 

To force the link and overwrite all conflicting files:

brew link --overwrite python3 

To list all files that would be deleted:

brew link --overwrite --dry-run python3 

but you have to copy/paste the command to force the link which is:

brew link --overwrite python3 

I think that you must have the version (the newer) installed.

Comments

6

On OS X High Sierra, I had to do this:

sudo install -d -o $(whoami) -g admin /usr/local/Frameworks brew uninstall --ignore-dependencies python brew install python python --version # should work, returns 2.7, which is a Python thing (it's weird, but ok) 

credit to https://gist.github.com/irazasyed/7732946#gistcomment-2235469

I think it's better than recursively chowning the /usr/local dir, but that may solve other problems ;)

Comments

3

You can follow these steps.

$ python3 --version $ brew unlink python@2 $ brew link python3 $ python3 --version 

All steps

Comments

2

brew switch to python3 by default, so if you want to still set python2 as default bin python, running:

brew unlink python && brew link python2 --force 

Comments

1

I wouldn't recommend playing around with the symlinks, it's not just to where python points, its the entire env around it as well that maybe mixing version

I would do this:

$ brew install pyenv $ pyenv install 3.7.3 $ pyenv global 3.7.3 

Comments

0

The problem with me is that I have so many different versions of python, so it opens up a different python3.7 even after I did brew link. I did the following additional steps to make it default after linking

First, open up the document setting up the path of python

 nano ~/.bash_profile 

Then something like this shows up:

# Setting PATH for Python 3.7 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}" export PATH # Setting PATH for Python 3.6 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}" export PATH 

The thing here is that my Python for brew framework is not in the Library Folder!! So I changed the framework for python 3.7, which looks like follows in my system

# Setting PATH for Python 3.7 # The original version is saved in .bash_profile.pysave PATH="/usr/local/Frameworks/Python.framework/Versions/3.7/bin:${PATH}" export PATH 

Change and save the file. Restart the computer, and typing in python3.7, I get the python I installed for brew.

Not sure if my case is applicable to everyone, but worth a try. Not sure if the framework path is the same for everyone, please made sure before trying out.

Comments

-1

This answer is for upgrading Python 2.7.10 to Python 2.7.11 on Mac OS X El Capitan . On Terminal type:

brew unlink python 

After that type on Terminal

brew install python 

Comments

-2

I use these commands to solve it.

mkdir /usr/local/lib mkdir /usr/local/lib/pkgconfig brew link python 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.