错误:没有名为cv2的模块 [英] Error: No module named cv2
问题描述
我在SO上已经发现了几个问题,但是我无法使用那里的答案来解决这个问题.
I have already found few questions at SO but i am unable to solve this problem using the answers there.
我是python的新手.我在Ubuntu 12.04中使用python.在我的/usr/local/lib
中,有两个python文件夹python 2.7
和python 3.2
. python 2.7
包含dist-packages和site-packages,而python 3.2
仅包含dist-packages.
I am new to python. I am having python in Ubuntu 12.04. In my /usr/local/lib
, there are two python folders python 2.7
and python 3.2
. python 2.7
contains dist-packages and site-packages while python 3.2
contains only dist-packages.
我正在尝试使用以下代码运行一个非常简单的opencv示例:
I am trying to run a very simple opencv example with the following code:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('image.JPG')
kernel = np.ones((5,5),np.float32)/25
dst = cv2.filter2D(img,-1,kernel)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(dst),plt.title('Averaging')
plt.xticks([]), plt.yticks([])
plt.show()
错误:没有名为cv2的模块
Error: No module named cv2
推荐答案
NB:此答案是上面评论的简短汇编.有关更多详细信息,请参阅以下问题的注释.
背景:OP正在使用SPE Stani's python editor
. OP已安装上述编辑器未检测到的OpenCV /opt/ros/hydro/lib/python2.7/dist-packages
.将此路径添加到PYTHONPATH不能解决问题.
Background : OP is using SPE Stani's python editor
. OP has installed OpenCV /opt/ros/hydro/lib/python2.7/dist-packages
which is not detected by the above mentioned editor. Adding this path to PYTHONPATH doesn't solve the issue.
解决方案(以下任意一项):
- 将此路径添加到
sys.path
并将其放置在每个文件中.
- Add this path to
sys.path
and put it in every file.
import sys
sys.path.append('/opt/ros/hydro/lib/python2.7/dist-packages')
import sys
sys.path.append('/opt/ros/hydro/lib/python2.7/dist-packages')
- 将
cv2.so
文件复制到sys.path
中的任何目录.
- Copy
cv2.so
file to any directory in thesys.path
.
这篇关于错误:没有名为cv2的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!