Python 没有名为 cv 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45675823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No module named cv
提问by Vallo
I'm trying to run this script:
我正在尝试运行此脚本:
https://github.com/openalpr/train-detector/blob/master/crop_plates.py
https://github.com/openalpr/train-detector/blob/master/crop_plates.py
I've never dealt with python before. First of all I had some syntax errors in the print lines. They were lacking parentheses...but I'm not sure if I get this error because of the Python version I installed or this was indeed a syntax error. After fixing the syntax error I'm receiving the following error:
我以前从未处理过python。首先,我在打印行中有一些语法错误。他们缺少括号......但我不确定我是否因为我安装的 Python 版本而收到此错误,或者这确实是一个语法错误。修复语法错误后,我收到以下错误:
C:\>py crop_plates.py
Traceback (most recent call last):
File "crop_plates.py", line 7, in <module>
import cv2, cv
ImportError: No module named cv
I did the following:
我做了以下事情:
Installed Python 2.7.5 32 bits.
安装了 Python 2.7.5 32 位。
Installed numpy 1.9.1 32 bits (also tried different versions)
安装 numpy 1.9.1 32 位(也试过不同版本)
Installed matplotlib 1.3.0.
安装了 matplotlib 1.3.0。
Installed OpenCv
安装 OpenCv
Copied cv2.pyd from
从复制 cv2.pyd
C:\Users\Me\Downloads\opencv\build\python.7\x86
to
到
C:\Python27\Lib\site-packages
But I can't find anywhere the cv.pyd file that I'm missing.
但是我在任何地方都找不到我丢失的 cv.pyd 文件。
I found references to this guide for installing Opencv but it's not working http://opencv.willowgarage.com/documentation/python/
我找到了安装 Opencv 的本指南的参考,但它不起作用 http://opencv.willowgarage.com/documentation/python/
Thank you very much,
非常感谢,
Edit: I'm running Python in Windows 7.
编辑:我在 Windows 7 中运行 Python。
回答by Computer Science Engineer
For ImportError: No module named cv
, try installing opencv-python
module using below command:
对于ImportError: No module named cv
,请尝试opencv-python
使用以下命令安装模块:
pip install opencv-python
回答by Gaultier
cv2.cv
doesn't exists in OpenCV 3.0. Use simply cv2
cv2.cv
在 OpenCV 3.0 中不存在。简单使用cv2
Also, the attribute is no more CV_HOUGH_GRADIENTbut HOUGH_GRADIENT
此外,属性不再是CV_HOUGH_GRADIENT而是HOUGH_GRADIENT
So what you looking for is probably:
所以你要找的可能是:
cv2.HOUGH_GRADIENT
回答by Yasin Yousif
OK , I searched for a while and find the following :
好的,我搜索了一段时间并找到了以下内容:
First: you may write:
import cv2.cv as cv
to solve your proplemcv
andcv2
are both interface for python , and now , the newest "cv2
" is the most used one , but clearly some libraries still usecv
and others (like yours) use mix of the two,What is different between all these OpenCV Python interfaces?
第一:你可以写:
import cv2.cv as cv
解决你的问题cv
并且cv2
都是 python 的接口,现在,最新的“cv2
”是最常用的一个,但显然有些库仍在使用,cv
而其他库(比如你的)使用两者的混合,所有这些 OpenCV Python 接口有什么不同?
回答by Fred Guth
It seems this code is using a old version of OpenCV. Unfortunately there is no mention of the exact version they used in their repo.
看来这段代码使用的是旧版本的 OpenCV。不幸的是,没有提到他们在他们的 repo 中使用的确切版本。
As the code is at least 2 years old, I would install opencv version 2.4.
由于代码至少有 2 年历史,我会安装 opencv 2.4 版。
pip install opencv-python==2.4
pip install opencv-python==2.4