解决bug“ImportError: numpy.core.multiarray failed to import”
在这之前升级scikit-image从老版本0.13.0到0.17.2,但运行pycharm工程出现如下bug:
from ._find_contours_cy import _get_contour_segments
File "skimage/measure/_find_contours_cy.pyx", line 7, in init skimage.measure._find_contours_cy
File "__init__.pxd", line 1038, in numpy.import_array
ImportError: numpy.core.multiarray failed to import
Process finished with exit code 1
经查,是numpy版本问题。
我的python版本是3.6.2
以下是解决措施:
卸载numpy 1.19.5
pip uninstall numpy
查看版本时,发现还有numpy 1.11.3,运行pycharm会有另外一个bug
import pandas # type: ignore[import]
File "/home/***/WGANpy36/lib/python3.6/site-packages/pandas/__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "/home/***/WGANpy36/lib/python3.6/site-packages/pandas/compat/numpy/__init__.py", line 10, in <module>
_np_version = np.__version__
AttributeError: module 'numpy' has no attribute '__version__'
Process finished with exit code 1
这说明,numpy 1.11.3与pandas的版本有冲突。
再次卸载numpy
安装numpy 1.15.0 (记得利用国内源,我用了清华源)
pip install numpy==1.15.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
虽然安装成果,但有报错,提醒了正确的版本1.5.1(敬佩pip)
再次安装numpy
pip install numpy==1.15.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip自动卸载了1.15.0,安装了1.15.1 (再次敬佩pip)
至此,运行pycharm工程正常。