[英]Why can't I import opencv3 even though the package is installed?
I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. 我目前正在运行Python 3.5并使用Anaconda的Spyder作为我的IDE。 I am running this on a Windows machine. 我在Windows机器上运行它。
When I write import cv3
at the top of my code, it returns the error ImportError: No module named 'cv3'
当我在代码顶部写入import cv3
时,它返回错误ImportError: No module named 'cv3'
I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3
in the Command Prompt. 我尝试使用命令conda install -c https://conda.binstar.org/menpo opencv3
在命令提示符中再次安装opencv3。 It is apparently already installed because it returned 它显然已经安装,因为它返回
Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3 3.1.0 py35_0 https://conda.binstar.org/menpo
Am I importing cv3 wrong? 我输入cv3错了吗? How do I fix this error? 我该如何解决这个错误?
Update: Tried import cv3
instead of import cv2
but got the following error: ImportError: cannot import name 'cv2'
. 更新:尝试import cv3
而不是import cv2
但出现以下错误: ImportError: cannot import name 'cv2'
。 The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. 关于这两个错误的措辞是不同的,所以python必须承认安装了opencv但是由于某种原因它不起作用。 Any ideas? 有任何想法吗?
具有讽刺意味的是,该模块仍然被称为cv2
因为它不代表opencv的版本,而是下面的实际C ++ API,与C API形成对比,命名为 - cv2 ...所以试试: import cv2
Problem solved by using command pip uninstall opencv-python
in the Command Prompt. 在命令提示符中使用命令pip uninstall opencv-python
解决了问题。
I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. 我曾尝试过几次opencv的安装,我想有人可能已经下载得非常糟糕,Anaconda试图读取那个。 I looked into the build of some of the other installations I attempted and some were for Python 2.7. 我研究了一些我尝试过的其他安装的构建,还有一些用于Python 2.7。 Maybe that contributed to the error. 也许这导致了错误。
Thankfully, this worked. 谢天谢地,这很有效。 Now import cv2
works perfectly. 现在import cv2
完美运行。 No errors. 没有错误。
I used the same approach to install the package. 我使用相同的方法来安装包。 However, I could not import the library using the name opencv3
. 但是,我无法使用名称opencv3
导入库。 I had to use cv2
which worked for me. 我不得不使用适合我的cv2
。
Elaborating on @zwer's answer, check the version of OpenCV after import cv2
. 详细说明@zwer的答案,请在import cv2
后检查OpenCV的版本。
>>> cv2.__version__
'3.1.0'
So basically it's calling the OpenCV3 library. 所以基本上它正在调用OpenCV3库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.