Joseph James Farrugia Joseph James Farrugia - 28 days ago 23
Python Question

NumPy: Import Error, Image Not Found OSX

Basically just started getting into Python and making the gradual switchover from Matlab.

I'm having trouble importing packages for use in my Python scripts.

I downloaded Anaconda (which, to my knowledge, installs Python) and proceeded to download "NumPy" through the command line in terminal.

I am using IDLE currently as my Python text editor, and all is well, if I save my .py file and run it through Terminal as, for example, python test.py. It finds the NumPy library and executes fine:

#!/usr/bin/env python
import numpy as np

array=np.zeros([5,5])
print(array)

[[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]]


However, trying to import numpy through terminal after activating the Python shell via Python3.5, the following happens.

>>> import numpy as np
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/__init__.py", line 184, in <module>
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-darwin.so, 10): Library not loaded: @loader_path/../../../../libmkl_intel_lp64.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-darwin.so
Reason: image not found


The same message comes up if I try to run the script through the Python shell in IDLE. I'm thinking it's looking for the library NumPy in the wrong place, but I'm not sure how to correct the issue.

Answer

Run the graphical installer for your operating system and version and make sure you select to install on "Macintosh HD". The installation you ran likely installed in your local Library folder (/Users/yourusername/Library), but the location being checked is the global library folder, /Library/.