Python – “no suitable image found” error when using numpy

macosnumpyosx-lionpython

I tried to use NumPy in Terminal, but the system gave me an error message like this:

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

How can I fix it? I installed Python 2.7.3 from official source and my machine is running OSX 10.7.4.

Best Answer

Your installation of NumPy is borked somehow: it detects that some of its core libraries (eg, multiarray.so) were compiled with a different version of the compiler or for a different architecture.

If you installed NumPy before updating your Python to 2.7.3, you have to reinstall it. You could find precompiled binaries, but as you've modified the original Python, they may not work for you.

At the same time, compiling NumPy on Mac OS X isn't particularly difficult. There are some environment variables to set beforehand, but otherwise, it's a straightforward process. This link should give you precious information.

Related Topic