josephmisiti
josephmisiti

Reputation: 9974

Installing Python modules on OSX using easy_install or setup.py install

I am running Snow Leapord 10.6 and trying to install the following python modules:

  1. numpy
  2. scipy
  3. matplotlib

I am running into problems because OSX contains two version of Python:

  1. /Library/Python/
  2. /System/Library/Frameworks/Python.framework/

It appears that when I execute the following command:

sudo easy_install -U {module}, the modules are being installed to the site-packages directory here:

bash-3.2$ ls -al /Library/Python/2.6/site-packages/
total 688
drwxrwxr-x  12 root  admin     408 Aug 24 23:26 .
drwxrwxr-x   3 root  admin     102 Feb 11  2010 ..
-rw-rw-r--   1 root  admin     119 Feb 11  2010 README
-rw-r--r--   1 root  admin     267 Aug 24 19:03 easy-install.pth
drwxr-xr-x   5 root  admin     170 Aug 24 10:42 nose-0.11.4-py2.6.egg
drwxr-xr-x  38 root  admin    1292 Aug 24 15:35 numpy
-rw-r--r--   1 root  admin    1618 Aug 24 15:35 numpy-2.0.0.dev8661-py2.6.egg-info
drwxr-xr-x  16 root  admin     544 Aug 24 19:07 numscons
drwxr-xr-x   4 root  admin     136 Aug 24 19:03 numscons-0.10.1-py2.6.egg
-rw-r--r--   1 root  admin     265 Aug 24 19:07 numscons-0.12.0dev-py2.6.egg-info
-rw-r--r--   1 root  admin  333959 Aug 23 11:51 setuptools-0.6c11-py2.6.egg
-rw-r--r--   1 root  admin      30 Aug 23 11:51 setuptools.pth

But, when I try to install scipy, I see the following error:

    config = setup_module.configuration(*args)
  File "scipy/setup.py", line 20, in configuration
    config.add_subpackage('special')
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 851, in add_subpackage
    caller_level = 2)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 834, in get_subpackage
    caller_level = caller_level + 1)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 766, in _get_configuration_from_setup_py
    ('.py', 'U', 1))
  File "scipy/special/setup.py", line 14, in <module>
    (numpy.__version__, numpy.__file__))
ValueError: numpy >= 1.4 is required (detected 1.2.1 from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/__init__.pyc)

So it appears that it is looking for an older version of numpy in my frameworks directory. I used import to see which version of numpy python was finding:

 python -c 'import numpy;print numpy.__version__'
1.2.1

And sure enough, it is looking in the frameworks directory even though I have a new version sitting in:

/Library/Python/2.6/site-packages/

I know import searches your local directory first, and then goes into PYTHONPATH, and then finally looks at sys.path. So I checked these out and I do not have PYTHONPATH set right now, and here is my sys.path:

/Library/Python/2.6/site-packages/setuptools-0.6c11-py2.6.egg
/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg
/Library/Python/2.6/site-packages/numscons-0.10.1-py2.6.egg
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload
/Library/Python/2.6/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode

If I change PYTHONPATH to /Library/Python/2.6/site-packages and then check the numpy revision I get the correct version:

bash-3.2$ python -c 'import numpy; print numpy.__version__'
2.0.0.dev8661

But when I run sudo python setup.py build/install scipy cannot find the right numpy, even though PYTHONPATH has been set.

Can anyone please help me out here?

Found this link that looks like it fixes my problem, but I cant seem to get it to work:

http://andreasjacobsen.com/2008/10/10/using-python-setuptools-on-the-mac/

Upvotes: 2

Views: 9996

Answers (6)

Elm662
Elm662

Reputation: 673

I had kind of similar problem, just to same some time of the people with the same issue, if you have two pythons in your system (say python2 and python3) and you wish to install say numpy for the new version (python3) go through these steps:

1- download numpy

2-unzip it

3- in terminal go to the unzipped folder

4-python3 setup.py install

Upvotes: 0

josephmisiti
josephmisiti

Reputation: 9974

The solution I came up with is the following.

1) Do not use the version of Python that comes pre-installed with OSX. Apple has apparently made some modifications to this and not everything builds. So, you need to install a development version of Python. Right now - I would suggest installing Python 2.7. Here is a blog post about how to do it:

https://medium.com/cs-math/a3eb146ebfb5

2) Once you have installed Python, you need to install the fortran libraries for the Scipy/Numpy installation. Use homebrew to do that (Do people really still use MacPorts ???)

http://brew.sh/

3) After you have home brew installed, install fortran

brew install gfortran

4) Now you can install scipy/numpy successfully with pip (Warning - it takes a while)

pip install -U numpy pip install -U scipy

DONE

Upvotes: 0

denis
denis

Reputation: 21937

Can you not just move the old numpy out of the way, temporarily ?

cd /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python
sudo mv numpy numpy-1.2.1  # mv back if need be

Upvotes: 0

mmmmmm
mmmmmm

Reputation: 32626

The issue is that the easy_install you are calling is the one for the Apple install with the frameworks in /System and the python is /usr/bin/python

To see what python gets installed view the easy_install script and see what the #! line says which python to use.

To get the correct easy_install you will need to install distibute or setuptools for the python in /Library (I would guess this is a python.org one with /usr/local/bin/python ). Then use that easy_install

I would note however that I do use @boocs solution of using Macports althogh if just after scipy etc and no other C libraries then other solutions show here will work, also see Enthought

Upvotes: 0

ustun
ustun

Reputation: 7021

Have you tried installing with pip? Also, try installing scitools, which should pull those you needed.

Upvotes: 2

Michael Kuhn
Michael Kuhn

Reputation: 8972

I think the easiest way would be to use MacPorts to install scipy. Here's an intro, though you probably want py26-scipy.

Upvotes: 2

Related Questions