我试图将numpy库加载到Ubuntu上的python3.8.0中。
from numpy import loadtxt
给出一个非常冗长的错误,没有解决方案:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 16, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray' from partially initialized module 'numpy.core' (most likely due to a circular import) (/usr/lib/python3/dist-packages/numpy/core/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name 'multiarray' from partially initialized module 'numpy.core' (most likely due to a circular import) (/usr/lib/python3/dist-packages/numpy/core/__init__.py)
根据我在Python circular importing?上看到的建议,我将导入行更改为导入所有numpy:
import numpy
但这也带来了同样的错误。
正如错误提示的那样,我尝试用pip重新安装numpy:
sudo pip install --upgrade --force-reinstall numpy
同样的错误也发生在
sudo pip3 install --upgrade --force-reinstall numpy
它起了作用,并安装了numpy-1.19.5。然而,这并没有解决导入问题。
我尝试从https://github.com/numpy/numpy/issues/9047实现一个解决方案,其中包括设置
export PYTHONPATH=/usr/lib/python3/dist-packages/$PYTHONPATH
中的~/..bashrc,但这也失败了。
我怎么才能进口蒙皮呢?
发布于 2021-02-19 22:17:49
问题是pip
和python
被链接到不同的版本。
解决方案是通过sudo /usr/bin/python3.8 -m pip uninstall numpy
和sudo /usr/bin/python3.8 install numpy
进行安装。
发布于 2021-02-19 21:53:40
看了一下循环导入之后,看起来您最好还是做import numpy
并相应地修改代码,而不是使用from
语法。
https://stackoverflow.com/questions/66285143
复制相似问题