numpy Importing the numpy C-exte

2022-05-01  本文已影响0人  王国的荣耀

Python 3.9.7 和 3.8.12 现已发布。Python 3.9.7 是 Python 编程语言的最新主要稳定版本,许多新功能和优化,自 3.9.6 以来已经有 187 次提交。而 Python 3.8 现在处于其生命周期的 “仅安全修复” 阶段,此次更新包含四个修复程序。

macos 安装 numpy

>>> import numpy
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/__init__.py", line 17, in <module>
    from . import multiarray
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/multiarray.py", line 14, in <module>
    from . import overrides
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): Symbol not found: ___addtf3
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/.dylibs/libgfortran.3.dylib
  Expected in: /usr/lib/libSystem.B.dylib

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/__init__.py", line 47, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.8 from "/usr/local/bin/python",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.3" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: dlopen(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): Symbol not found: ___addtf3
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/.dylibs/libgfortran.3.dylib
  Expected in: /usr/lib/libSystem.B.dylib

pip install pbr
pip install virtualenvwrapper

otool - L /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/.dylibs/libgfortran.3.dylib
显示的依赖为: /usr/lib/libSystem.B.dylib。
其中libSystem.B.dylib是老版本系统的东西。

/usr/local/Cellar/gcc/11.2.0/lib/gcc/11/libgfortran.dylib

otool -L /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/.dylibs/libgfortran.3.dylib 
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/.dylibs/libgfortran.3.dylib:
    /DLC/numpy/.dylibs/libgfortran.3.dylib (compatibility version 4.0.0, current version 4.0.0)
    @loader_path/libquadmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
    @loader_path/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

解决办法:使用anaconda;使用anaconda自带的numpy构建。

下载anaconda

https://www.anaconda.com/

macos 安装 python-Levenshtein

gcc -bundle -undefined dynamic_lookup -g -L/usr/local/opt/libffi/lib -I/usr/local/opt/libffi/include -arch x86_64 build/temp.macosx-10.9-x86_64-3.8/Levenshtein/_levenshtein.o -o build/lib.macosx-10.9-x86_64-3.8/Levenshtein/_levenshtein.cpython-38-darwin.so
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1

python3 -m pip install python-levenshtein
或者如果您想在系统范围内安装执行:sudo -H python3 -m pip install python-levenshtein。

上一篇下一篇

猜你喜欢

热点阅读