• 系统环境:Windows10
  • Python环境:Anaconda + Python3.6.3
  • OpenCV:3.4.3
    安装完OpenCV库之后,导入cv2时出现numpy.core.multiarray failed to import问题:
(D:\Users\XXX\Anaconda3) C:\Users\XXX>python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import

问题原因: opencv3版本与numpy的版本不匹配,可以尝试更新numpy的版本试试.
解决办法:
在控制台窗口中输入:

pip install -U numpy

出现以下信息表示降级完成.

(D:\Users\XXX\Anaconda3) C:\Users\XXX>pip install -U numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/51/70/7096a735b27359dbc0c380b23b9c9bd05fea62233f95849c43a6b02c5f40/numpy-1.15.4-cp36-none-win_amd64.whl (13.5MB)
    100% |████████████████████████████████| 13.5MB 27kB/s
Installing collected packages: numpy
  Found existing installation: numpy 1.12.0
    Uninstalling numpy-1.12.0:
      Successfully uninstalled numpy-1.12.0
Successfully installed numpy-1.15.4

再次测试,import cv2成功!

(D:\Users\XXX\Anaconda3) C:\Users\XXX>python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐