Python site packages directory

homebrewpythonterminal

I have for some reason two locations for python site packages.

Python itself is here:

> $ which python
> /Library/Frameworks/Python.framework/Versions/2.7/bin/python

My Path Variable is:

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/opt/opengeo/pgsql/9.1/bin

xlrd is installed here and can be accessed from python

> $ pip install xlrd
> Requirement already satisfied (use --upgrade to upgrade): xlrd in /Library/Python/2.7/site-packages

$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlrd
>>> 

numpy is installed here and can not be accessed from python

> $ pip install numpy
> Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python2.7/site-packages

$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

What do I have to do to get numpy also working with python. I am looking for the 'cleanest solution'.

Best Answer

As a short-term solution, you should be able to run

cp /usr/local/lib/python2.7/site-packages/numpy* /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

as the versions of python are the same, and /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages is (amongst other places) where your python binary will be looking for modules.

I'm concerned that /usr/bin/python doesn't exist, as this is what is shipped with OSX and is required for some system/OS stuff to run. The reason you have so many site-packages directories (you actually have more than you listed in your question) is that it seems like you've installed a python.org version (the /Library/Frameworks/... one) and perhaps a third-party version from Homebrew or some other package manager (MacPorts by default installs into the /opt/local directory). Your version of pip was also installed from that source, so if you want to use the python.org version as your default then you'll need to install pip again (make sure you use the setuptools version, as distribute is defunct). After that's all done, you can then run pip install numpy --upgrade to make sure you've got the latest version, which is 1.7.1 currently.