在Ubuntu上安装适用于Python的OpenCV,出现ImportError:没有名为cv2.cv的模块
我有一个Ubuntu 14.04系统,我想在其上安装OpenCV并将其与Python 2.x一起使用.
I have an Ubuntu 14.04 system, on which I want to install OpenCV and use it with Python 2.x.
我按照以下说明安装了OpenCV: https://help.ubuntu.com/community/OpenCV
I installed OpenCV using the instructions here: https://help.ubuntu.com/community/OpenCV
安装似乎正常运行,没有错误,脚本以输出结尾
The install seemed to run properly, no errors, the script ended with output
OpenCV 2.4.9 ready to be used
当我尝试运行示例Python脚本时,得到以下信息:
When I try to run the sample Python script, I get the following:
$ python opencv.py
Traceback (most recent call last):
File "opencv.py", line 1, in <module>
from cv2.cv import *
ImportError: No module named cv2.cv
我怀疑我知道为什么,我只是不知道如何解决它. OpenCV安装到运行安装脚本时所在的当前目录,它是主文件夹的子目录.
I suspect I know why, I just don't know how to fix it. OpenCV installed to the current directory I was in when I ran the install script, it's a subdirectory of my home folder.
其他在安装后出现此导入错误的人似乎遇到了路径问题,并很幸运将其添加到他们的代码中:
Others who get this import error after install seem to be having a path issue, and have luck adding this to their code:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
或使用同一目录更新其PYTHONPATH.我尝试添加该代码,但没有任何区别.我在"site-packages"目录中看不到任何文件.我应该在该目录中完成安装吗?我想安装说明会清楚地说明这一点.我怀疑我的问题与Python没有找到OpenCV安装有关,但我不确定如何继续.
or updating their PYTHONPATH with that same directory. I tried adding that code, it doesn't make a difference. I don't see any files in the "site-packages" directory. Should I have done the install in that directory? I imagine the installation instructions would have spelled that out. I suspect that my problem has to do with Python not finding the OpenCV install, but I'm not sure how to proceed.
请帮助我尽可能简单地获得可用的OpenCV安装.
Please help me get a usable install of OpenCV as simply as possible.
我认为您没有python-opencv
软件包.
我遇到了完全相同的问题,并且
I had the exact same problem and
sudo apt-get install python-opencv
为我解决了这个问题.
您可以通过以下链接安装opencv https://www.learnopencv.com/install-opencv3-on-ubuntu/ 这个对我有用 . apt-get install不包含许多opencv软件包
you can install opencv from the following link https://www.learnopencv.com/install-opencv3-on-ubuntu/ It works for me . apt-get install doesnt contain many packages of opencv