简体   繁体   中英

Homebrew Python and writing to /Library/Python/2.7/site-packages/?

Is there a definitive guide for how to install Homebrew's Python properly, along with pip, virtualenv, virtualenvwrapper etc.?

I've read the following pages:

https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
http://osxastrotricks.wordpress.com/2012/05/02/python-setup-with-homebrew/
http://skipperkongen.dk/2011/11/13/installing-django-in-virtual-environment-on-mac/
http://www.thisisthegreenroom.com/2011/installing-python-numpy-scipy-matplotlib-and-ipython-on-lion/
http://youshoulddoityourself.blogspot.com.au/2010/11/test.html

I have OSX 10.8 (Mountain Lion) DP3, and I installed the XCode Command Line Tools.

I also installed XQuartz as well, just in case (10.8 doesn't provide it).

I then ran:

brew install python  --universal --framework

I added the following to my ~/.bash_profile :

export PATH="/usr/local/bin:/usr/local/share/python:${PATH}"

I then ran:

sudo easy_install pip

which seemed to work.

I check where pip's installed:

 Victors-MacBook-Pro:~ victorhooi$ which pip
/usr/local/bin/pip

However, when I try to pip install packages, I get an error complaining about not being able to write to /Library/Python/2.7/site-packages:

running install_lib

creating /Library/Python/2.7/site-packages/yolk

error: could not create '/Library/Python/2.7/site-packages/yolk': Permission denied

----------------------------------------
Command /usr/bin/python -c "import  setuptools;__file__='/Users/victorhooi/build/yolk/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/gg/m37t1rkx4zj7z54ls487jfc40000gn/T/pip-ap7LSB-record/install-record.txt failed with error code 1 in /Users/victorhooi/build/yolk
Storing complete log in /Users/victorhooi/Library/Logs/pip.log

My understanding was that Homebrew's Python would install into it's own site-packages, and I wouldn't need to do weird chown's all over the filesystem tree to get things to work?

Cheers, Victor

Meanwhile, homebrew's python has evolved:

  • Python installed via brew no longer tries to write to /Library/Python .
  • Homebrew's Python now always uses its own site-packages.
  • pip (and distribute) is installed automatically.
  • The "--framework" option is not needed. Homebrew defaults to it now.
  • XQuartz is needed (unfortunately) because the Tk headers link to X11 headers.

Your PATH in the .bashrc is correct (and still needed).

Please, as someone who has been exactly where you are, start using virtual environments first, then pip and the rest. They are awesome, and will solve this and many future problems.

Now that there is Mountain Lion 10.8.2 out and I had a legacy Python 2.7 install from Lion things just didn't work. Whatever I tried, Python wanted to access /Library/.. No good. The easy solution is to brew uninstall python and then brew install python That solves pretty much all Python related problems with homebrew on ML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM