Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 755
victorhooi Avatar asked Jun 07 '12 09:06

victorhooi


People also ask

Does pip work with Python 2?

To use pip, first install a custom version of Python 2. pip is then installed with it. You can then use the pip command to create a virtualenv and install modules.

What is Python site packages?

site-packages is the target directory of manually built Python packages. When you build and install Python packages from source (using distutils, probably by executing python setup.py install ), you will find the installed modules in site-packages by default.

Which version of Python is homebrew?

[email protected] — Homebrew Formulae.


2 Answers

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).

like image 159
Samuel John Avatar answered Oct 19 '22 01:10

Samuel John


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.

like image 42
nathancahill Avatar answered Oct 19 '22 01:10

nathancahill