NumPy:导入错误,图像未找到OSX

时间:2016-04-29 17:17:30

标签: python macos numpy terminal

基本上刚开始进入Python并从Matlab逐步转换。

我在导入包以在我的Python脚本中使用时遇到问题。

我下载了Anaconda(据我所知,安装了Python)并继续通过终端中的命令行下载“NumPy”。

我目前使用IDLE作为我的Python文本编辑器,如果我保存我的.py文件并通过终端运行它,例如python test.py,一切都很好。它找到NumPy库并执行正常:

#!/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.]]

但是,尝试通过Python3.5激活Python shell后通过终端导入numpy,会发生以下情况。

>>> 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

如果我尝试通过IDLE中的Python shell运行脚本,则会出现相同的消息。我在想它在错误的地方寻找NumPy库,但我不确定如何纠正这个问题。

2 个答案:

答案 0 :(得分:0)

运行适用于您的操作系统和版本的图形安装程序,并确保选择安装在&#34; Macintosh HD&#34;上。您运行的安装可能安装在本地库文件夹(/Users/yourusername/Library)中,但正在检查的位置是全局库文件夹/Library/

答案 1 :(得分:0)

在shell中点击&#34; python&#34;并打开shell配置。在exe中,选择以下行:&#34; /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7 [v2.7.10]&#34;然后单击done并重新启动python。