错误:没有名为cv2的模块 [英] Error: No module named cv2

查看:109
本文介绍了错误:没有名为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.7python 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.

解决方案(以下任意一项):

  1. 将此路径添加到sys.path并将其放置在每个文件中.
  1. 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')

  1. cv2.so文件复制到sys.path中的任何目录.
  1. Copy cv2.so file to any directory in the sys.path.

这篇关于错误:没有名为cv2的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆