2

I'm following the Scrapy installation guide to install a fresh copy of python (2.7.11) despite I already have 2.6, 2.7.10 and 3.4.0. The installation was going fine until the final step with these errors

==> Pouring python-2.7.11.el_capitan.bottle.2.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.4/bin/2to3
Error: Permission denied - /usr/local/Frameworks

Moreover

ls -l /usr/local/Frameworks
ls: /usr/local/Frameworks: No such file or directory

and

ls -l /usr/local/bin/2to3
lrwxr-xr-x  1 root  wheel  66  7 Apr  2014 /usr/local/bin/2to3 -> ../../../Library/Frameworks/Python.framework/Versions/3.4/bin/2to3

My Questions:

1) should I have done sudo brew install python instead of brew install python? Hopefully I don't need to uninstall 2.7.11 & start over.

2) If I do the two steps they suggest rm '/usr/local/bin/2to3' and brew link --overwrite python, would I still be able to run python 3.4.0 for non-Scrapy purposes? Presumably I should do these with sudo?

3) If I did #2, would the permission problem on /usr/local/Frameworks resolve itself or do I need to do something else?

Follow up:

The suggestion to set up virtualenv is probably a good one. But I'd imagine I probably need to get the install completed first.

I have now removed 2to3. I also tried to run brew link --overwrite python with sudo but it came back with this cowardly refusing to sudo brew link msg so I just went ahead and did it without sudo.

But brew link still failed on permissions

brew link --overwrite python
Linking /usr/local/Cellar/python/2.7.11... Error: Permission denied - /usr/local/Frameworks

However

ls -l /usr/local/Frameworks
ls: /usr/local/Frameworks: No such file or directory

Moreover, a lot of python related links in /usr/local/bin to the existing 3.4.0 (those links owned by root) and the new 2.7.11 (owned by me).

So what do I do now? Thanks a lot.

rockhammer
  • 957
  • 2
  • 13
  • 38
  • I would recommend using a [virtual environment](https://virtualenv.pypa.io/en/stable/) and use every configuration you want – eLRuLL May 27 '16 at 16:41
  • Thanks, eLRuLL. Your suggestion to set up virtualenv seems to make sense. But do I not need to complete installation first? I've tried to do the steps brew suggested in the original errmsgs but it still could not do the linking due to permissions on a file/folder that does not exist! – rockhammer May 28 '16 at 01:43

2 Answers2

3

Based on numerous posts from various fora, the most recommended best practice is to have homebrew install all versions of python you need, leave the OSX bundled python alone (& unused) and remove all other versions because homebrew does not necessarily play nice with them.

According to this, homebrew is supposed to be able to handle co-existing 2.7 & 3.x pythons. So I have followed this advice to remove the 3.4 that I installed previously myself directly from python.org.

I further followed the recommendations brew doctor provided, which were very similar to the steps mentioned in the link above on how to remove non-homebrew python. Subsequently

brew link --overwrite python
Linking /usr/local/Cellar/python/2.7.11... 5 symlinks created

and

brew doctor
Your system is ready to brew.

So it looks like 2.7.11 installed by homebrew is finally completed.

I will now use homebrew to install the latest 3.x version and update this post. Should that be successful, I will further set up virtualenv to install Scrapy.

Follow Up:

brew install python3 successfully installed Python 3.5.1

pip install virtualenv successfully installed virtualenv 15.0.1

virtualenv -p /usr/local/bin/python2.7 Scrapy successfully set up "Scrapy" virtual environment using 2.7

source Scrapy/bin/activate started up "Scrapy" virtual env

pip install lxml successfully installed lxml 3.6.0

pip install Scrapy successfully installed Scrapy 1.1.0

pip freeze > Scrapy/requirements.txt produced list of dependencies

deactivate exited "Scrapy" virtual env

Will try out Scrapy tutorial tomorrow to see if all these actually worked

Community
  • 1
  • 1
rockhammer
  • 957
  • 2
  • 13
  • 38
  • You may also need to do the following: `sudo mkdir /usr/local/Frameworks` `sudo chown foo:bar /usr/local/Frameworks` `chmod 755 /usr/local/Frameworks` `brew link --overwrite python` – bmoran Jan 05 '17 at 14:13
1

I just ran into a similar issue myself, here's what I did and I was able to brew link python:

sudo mkdir /usr/local/Frameworks
sudo chown {your username}:{your usergroup} /usr/local/Frameworks/