在opencv安装后在Python中导入cv2时出错

时间:2019-01-20 15:17:15

标签: python opencv

我已经成功安装了OpenCV,但是当我尝试将其导入Python时,出现以下错误。

在Python 2.7中,我得到了

$ echo $EDITOR
vim

在Python 3.6中,出现此错误

[imukunya@li165-244 site-packages]$ python

Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import cv2
>>> ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import

我已经尝试使用[imukunya@li165-244 site-packages]$ python3.6 Python 3.6.5 (default, Apr 10 2018, 17:08:37) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dynamic module does not define module export function (PyInit_cv2)

安装NumPy

1 个答案:

答案 0 :(得分:0)

请尝试执行以下命令。然后,请验证您的代码是否正常工作。

python -m pip install opencv-contrib-python