Python – Installing numpy Lion with Python 2.7

numpyosx-lionpython

I am working on a OS X 10.7 with Python 2.7 from python.org and XCode 4.2.

  1. Following these instructions, I tried changing the CC, CXX,
    and FFLAGS variables and install with sudo pip install numpy.
    However, the installation still looks for gcc-4.2.
  2. I tried
    installing gcc-4.2 through MacPorts but get that Error: gcc42
    does not build on Snow Leopard or later.
  3. When I install numpy from the precompiled binary on sourceforge, I get the following error:

    import numpy

    Traceback (most recent call last):

    File "", line 1, in

    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 137, in

    import add_newdocs
    

    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in

    from numpy.lib import add_newdoc
    

    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 4, in

    from type_check import *
    

    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in

    import numpy.core.numeric as _nx
    

    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 5, in

    import multiarray
    

    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper

Any help?

Best Answer

If I recall correctly the precompiled binary on source forge is 32-bit. It took me ages to get Numpy, Scipy, and Matplotlib set up on my macbook, it's definitely much harder than it should be.

I believe that your best option is the Scipy superpack. Before using the superpack you need to update to Xcode 4.3.2

So I just installed python 2.7.2 from python.org, grabbed the superpack, and now have numpy working on my machine. After installing python 2.7.2, I did sudo pip uninstall numpy, which didn't remove enough. So I cd'd into /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ and moved both the numpy directory and the numpy egg to "old" versions of themselves. Then I ran sh install_superpack.sh and answered no to the "are you installing from a repository cloned to this machine(pretty important lol, hit yes without thinking the first time).

However, now I'm able to do this:

$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import matplotlib

With no problems :)