python-3.x - 在 MacOS 中导入 numpy c-extensions 失败
问题描述
导入numpy c-extensions失败 我试图在终端中使用numpy,当我导入它时它返回一个错误。但是当我在pytharm Python控制台中导入numpy时,它运行良好。我有python 2.7.10和3.7.5, pytharm 中使用了 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
错误信息:
Blockquote Python 3.7.5(默认,2019 年 11 月 1 日,02:16:32)[Clang 11.0.0 (clang-1100.0.33.8)] on darwin 键入“帮助”、“版权”、“信用”或“许可证”更多信息。
导入numpy Traceback(最近一次调用最后):文件“ /Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/init.py”,第 17 行,从 .import multiarray 文件“/Users/chuck/Library/Python/3.7/lib/python/site-packages/numpy/core/multiarray.py”,第 14 行,从 .import 覆盖文件“/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 预期在:/Users/chuck/Library/Python/3.7/lib 中的 /usr/lib/libSystem.B.dylib /python/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib
在处理上述异常的过程中,又出现了一个异常:
回溯(最后一次调用):文件“”,第 1 行,在文件“/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 行,在 raise ImportError(msg) ImportError 中:
重要提示:请阅读本文以获取有关如何解决此问题的建议!
导入 numpy c-extensions 失败。- 尝试卸载并重新安装 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): Symbol not found: ___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
解决方案
我这样解决了这个问题:
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
推荐阅读
- r - 将所有数据的平均值移动到当前值
- r - 按组更改 ggplot2 中的 geom_*(例如,一组是线,下一组是点)
- deprecated - 函数 create_function() 已弃用
- android - CountDownTimer 没有取消
- python - 通过循环查找/存储斐波那契数列的前 50 个项
- c++ - C++ 中的运算符优先级
- powershell - 为什么 $env:username 和 [environment]::username 会返回不同的用户?
- c# - 如何在统一游戏中设置登录 Google Play 游戏服务
- java - FFmpeg 无法在 android 10 上运行,使用空消息进入 onFailure(String message)
- python - python/pandas 将列折叠为日期时间季度