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

标签 python opencv

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

在Python 2.7中,我得到了这个

[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

在Python 3.6中,出现此错误
[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)

我已经尝试使用$~python3 -m pip install numpy -I安装NumPy

最佳答案

请尝试执行以下命令。然后,请验证您的代码是否有效。

python -m pip安装opencv-contrib-python

关于python - 在opencv安装后在Python中导入cv2时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54277875/

相关文章:

python - 为什么 python 需要 global 关键字而 C/C++ 不需要?

python - 使用seaborn.objects接口(interface)绘制回归置信区间(v0.12)

python - 如何将 Octave 添加到我的 PATH 以使用 oct2py?

python - 使用 Motor AsyncIO 和 Pytest 测试 MongoDB 功能

opencv - cv::MatExpr 的目的是什么?

python - Tensorflow 教程 : Duplicated Shuffling in the Input Pipeline

opencv - 深度学习 - 如何执行 RANDOM CROP 并且不丢失数据中的任何信息(更改地面实况标签)

python - 在 python 中安装 opencv

c++ - 从 cvShowImage 调整 View 大小

android - 编译包含OpenCV header 的JNI库