简体   繁体   English

为什么即使安装了软件包也无法导入opencv3?

[英]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.

相关问题 Anaconda:即使安装了 opencv,也无法导入 cv2(如何为 python3 安装 opencv3) - Anaconda: cannot import cv2 even though opencv is installed (how to install opencv3 for python3) pyautogui / pyscreeze 找不到枕头,即使它已成功安装到同一个 package 文件夹中,我可以导入它 - pyautogui / pyscreeze can't find pillow even though it is successfully installed into the same package folder and I can import it 即使安装了 pygame 也无法导入 - Can't import pygame even though it is installed 即使正确安装,导入包也会出错 - Import package error even though it is properly installed 即使 conda 说已安装 Numpy 也无法导入 - Numpy can't import even though conda says installed 即使安装了软件包,也无法解析 python 导入模块 - Can't resolve python import module even though packages are installed 即使安装正确,也无法导入pmdarima - Can't import pmdarima even though it's installed properly 即使已安装,也无法导入pty模块 - Can't import pty module even though it's installed python3即使安装了也无法导入dbus - python3 Can't import dbus even though it's installed 即使它安装在我的机器上也无法导入 nltk - Can't import nltk even though it is installed on my machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM