Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Brew fails to install Python: can not symlink

I'm trying to install python 2.7 on the latest version of OSX using brew but I get the following error...

.app bundles were installed.
Run `brew linkapps` to symlink these to /Applications.
Warning: Could not link python. Unlinking...
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link python'

Possible conflicting files are:
/usr/local/bin/pip
/usr/local/bin/easy_install-2.7
/usr/local/bin/easy_install

Would anyone know how to fix this error? I tried brew link python but this did not work. I'm new to Linux/OSX, so if this is really obvious, I would still appreciate it if someone could point me in the right direction!

like image 329
Jim Avatar asked Feb 23 '14 22:02

Jim


3 Answers

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
like image 86
liberborn Avatar answered Nov 15 '22 18:11

liberborn


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.

like image 1
Nils Avatar answered Nov 15 '22 16:11

Nils


The most likely answer is that you have somehow installed executables (notably pip and easy-install) that Homebrew packages with it's install of Python outside of the Homebrew workflow. Because Homebrew is not managing these executables (that is, the executables are not symlinks to the versions stored in Homebrew's Cellar repository), its default action is to not overwrite these executables. There are two options you have to resolve this:

  1. You can remove the files that are blocking the installation. Depending on how you installed the executables previously, you might have to do this through manual rm commands. Once you do that, you can run brew link python and Homebrew will happily form the symlinks now that there are no pre-existing executables.

  2. You can tell Homebrew you don't actually care that those executables exist, and you want to overwrite them anyways by using brew link --overwrite python as described in this answer.

In either case, be aware that both pip and easy-install will have dependency files in a site-packages folder somewhere on your computer from their original installation. It would be advisable for you to audit your Python install and your computer for extraneous site-packages folders.

like image 1
David Antaramian Avatar answered Nov 15 '22 18:11

David Antaramian