【问题标题】:Importing the numpy c-extensions failed in MacOS在 MacOS 中导入 numpy c-extensions 失败
【发布时间】:2020-04-14 13:59:20
【问题描述】:

导入 numpy c 扩展失败 我正在尝试在终端中使用 numpy,当我导入它时它返回一个错误。但是当我在 pytharm Python 控制台中导入 numpy 时,它运行良好。我有 python 2.7.10 和 3.7.5,python 3.7.5 用于皮塔姆。我在所有版本的 python 上卸载了 numpy 并仅在 python 3.7.5 上重新安装它,但它返回了相同的错误。我通过命令行输入重新安装软件包:

 python3 -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose

但它也返回了相同的错误。我猜这是一个多环境问题。 尝试像这样卸载并安装 numpy 和 setuptools:

pip uninstall -y numpy

pip uninstall -y setuptools

pip install setuptools

pip install numpy

但它也返回了同样的错误。

我的python3点子列表:

absl-py              0.9.0   
aiodns               2.0.0   
aiohttp              3.5.4   
appnope              0.1.0   
astor                0.8.1   
async-timeout        3.0.1   
attrs                19.1.0  
backcall             0.1.0   
beautifulsoup4       4.5.3   
bleach               3.1.0   
browsermob-proxy     0.8.0   
bs4                  0.0.1   
cchardet             2.1.4   
certifi              2019.3.9
cffi                 1.12.3  
chardet              3.0.4   
cssselect            1.0.3   
cycler               0.10.0  
decorator            4.4.1   
defusedxml           0.6.0   
entrypoints          0.3     
fake-useragent       0.1.11  
gast                 0.3.2   
google-pasta         0.1.8   
grpcio               1.26.0  
h5py                 2.10.0  
idna                 2.6     
importlib-metadata   1.3.0   
ipykernel            5.1.3   
ipython              5.4.1   
ipython-genutils     0.2.0   
ipywidgets           7.5.1   
jedi                 0.15.2  
Jinja2               2.10.3  
joblib               0.14.1  
jsonschema           3.2.0   
jupyter              1.0.0   
jupyter-client       5.3.4   
jupyter-console      5.2.0   
jupyter-core         4.6.1   
Keras                2.2.4   
Keras-Applications   1.0.8   
Keras-Preprocessing  1.1.0   
kiwisolver           1.1.0   
lxml                 4.3.3   
Markdown             3.1.1   
MarkupSafe           1.1.1   
matplotlib           3.1.2   
mistune              0.8.4   
more-itertools       8.0.2   
mpmath               1.1.0   
multidict            4.5.2   
nbconvert            5.6.1   
nbformat             4.4.0   
nose                 1.3.7   
notebook             6.0.2   
ntplib               0.3.3   
numpy                1.17.4  
opencv-python        4.1.2.30
pandas               0.25.3  
pandocfilters        1.4.2   
parso                0.5.2   
pexpect              4.7.0   
pickleshare          0.7.5   
Pillow               6.2.1   
pip                  19.3.1  
prometheus-client    0.7.1   
prompt-toolkit       1.0.18  
protobuf             3.11.2  
ptyprocess           0.6.0   
pycares              3.0.0   
pycparser            2.19    
pycrypto             2.6.1   
Pygments             2.5.2   
PyMySQL              0.9.3   
pyparsing            2.4.5   
pyquery              1.4.0   
pyrsistent           0.15.6  
python-dateutil      2.8.1   
pytz                 2019.3  
PyYAML               5.2     
pyzmq                18.1.1  
qtconsole            4.6.0   
redis                3.3.11  
requests             2.18.4  
scikit-learn         0.22    
scipy                1.4.1   
selenium             3.11.0  
Send2Trash           1.5.0   
setuptools           42.0.2  
simplegeneric        0.8.1   
six                  1.13.0  
sklearn              0.0     
soupsieve            1.9.1   
splinter             0.13.0  
sympy                1.5     
tensorboard          1.14.0  
tensorflow           1.14.0  
tensorflow-estimator 1.14.0  
termcolor            1.1.0   
terminado            0.8.3   
testpath             0.4.4   
tornado              6.0.3   
traitlets            4.3.3   
urllib3              1.22    
wcwidth              0.1.7   
webencodings         0.5.1   
Werkzeug             0.16.0  
wheel                0.33.6  
widgetsnbextension   3.5.1   
wrapcache            1.0.8   
wrapt                1.11.1  
xvfbwrapper          0.2.9   
yarl                 1.3.0   
zipp                 0.6.0  

我该如何解决这个问题?

重现代码示例:

import numpy

错误信息:

块引用 Python 3.7.5(默认,2019 年 11 月 1 日,02:16:32)[Clang 11.0.0 (clang-1100.0.33.8)] on darwin 输入“帮助”、“版权”、“信用”或 “许可证”了解更多信息。

import numpy Traceback(最近一次调用最后一次):文件“/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/init.py”, 第 17 行,在 从 。导入多数组文件“/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/multiarray.py”, 第 14 行,在 从 。导入覆盖文件“/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/overrides.py”, 第 7 行,在 从 numpy.core._multiarray_umath 导入(ImportError: dlopen(/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-37m-darwin.so, 2):未找到符号:___addtf3 引用自: /Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib 预期在:/usr/lib/libSystem.B.dylib 在 /Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib

在处理上述异常的过程中,又发生了一个异常:

Traceback(最近一次调用最后一次):文件“”,第 1 行,in 文件 "/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/init.py", 第 142 行,在 从 。导入核心文件“/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/init.py”, 第 47 行,在 引发 ImportError(msg) ImportError:

重要提示:请阅读本文以获取有关如何解决此问题的建议!

导入 numpy c 扩展失败。 - 尝试卸载并重新安装 numpy。 - 如果您已经这样做了,那么: 1. 检查您是否希望使用“/usr/local/opt/python/bin/python3.7”中的 Python3.7, 并且您的 PATH 或 PYTHONPATH 中没有目录可以 干扰您尝试使用的 Python 和 numpy 版本“1.17.4”。 2. 如果 (1) 看起来不错,您可以在以下位置打开一个新问题 https://github.com/numpy/numpy/issues。请包括以下详细信息: - 你是如何安装 Python 的 - 你如何安装 numpy - 您的操作系统 - 无论您是否安装了多个 Python 版本 - 如果您从源代码构建,您的编译器版本和理想的构建日志

  • 如果您正在使用 numpy git 存储库,请尝试 git clean -xdf(删除所有不受版本控制的文件)并重建 numpy。

注意:这个错误有很多可能的原因,所以请不要评论 一个关于此的现有问题 - 改为打开一个新问题。

原来的错误是: dlopen(/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-37m-darwin.so, 2):未找到符号:___addtf3 引用自: /Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib 预期在:/usr/lib/libSystem.B.dylib 在 /Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib

【问题讨论】:

    标签: python-3.x macos numpy


    【解决方案1】:

    我这样解决了这个问题:

    bogon:bin chuck$ brew unlink python3
    Unlinking /usr/local/Cellar/python/3.7.5... 0 symlinks removed
    
    bogon:bin chuck$ brew link python3
    Linking /usr/local/Cellar/python/3.7.5... 
    Error: Could not symlink bin/easy_install-3.7
    Target /usr/local/bin/easy_install-3.7
    already exists. You may want to remove it:
      rm '/usr/local/bin/easy_install-3.7'
    To force the link and overwrite all conflicting files:
      brew link --overwrite python
    To list all files that would be deleted:
      brew link --overwrite --dry-run python
    
    bogon:bin chuck$ brew link --overwrite python3
    Linking /usr/local/Cellar/python/3.7.5... 24 symlinks created
    

    【讨论】:

      猜你喜欢
      • 2020-03-11
      • 2021-12-03
      • 2012-11-13
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2021-03-20
      相关资源
      最近更新 更多