简体   繁体   English

ModuleNotFoundError:没有名为“cv2”的模块

[英]ModuleNotFoundError: No module named 'cv2'

I have been working on this error for a long time now.我已经处理这个错误很长时间了。 I have Python 3.6 and Python 2.7.我有 Python 3.6 和 Python 2.7。 I have tried to install opencv 2 and 3 in Python 2.7 and Python 3.6 respectively.我曾尝试分别在 Python 2.7 和 Python 3.6 中安装 opencv 2 和 3。 I know the python interpreter I am using and I can interchange between them when I want.我知道我正在使用的 python 解释器,我可以在需要时在它们之间进行交换。

When I run Python interpreter and write import cv2 it does import it.当我运行 Python 解释器并编写import cv2时,它确实会导入它。 When I run the code from command prompt it says ModuleNotFoundError: No module named 'cv2' .当我从命令提示符运行代码时,它显示 ModuleNotFoundError: No module named 'cv2' The module is installed.模块已安装。 The cv2.pyd file is in C:\Python27\Lib\site-packages I have attached a screen shot which shows the modules in Python27 cv2.pyd 文件位于C:\Python27\Lib\site-packages我附上了一个屏幕截图,显示了 Python27 中的模块

在此处输入图像描述

I have used pip install opencv-python .我用过pip install opencv-python I have downloaded the module from different sites and manually copy pasted it in the correct folder.我已经从不同的站点下载了模块并手动将其复制粘贴到正确的文件夹中。 Nothing works and I am seriously short of ideas now.没有任何效果,我现在严重缺乏想法。

EDIT: I am on windows 10 with python 3.6 installed through anaconda and python 2.7 installed directly.编辑:我在 windows 10 上,通过 anaconda 和 Z23EEEB4347BDD26BDDFC6B27 直接安装了 python 3.6。 Both have their variables set in the path两者都在路径中设置了变量

In Windows 10 you can install it as在 Windows 10 中,您可以将其安装为

pip install opencv-python

this will allow you to import cv2 module这将允许您导入 cv2 模块

Faced with the same issue on Windows 10 I downloaded the open cv binary from the Unofficial Windows Binaries for Python Extension Packages .面对 Windows 10 上的相同问题,我从Unofficial Windows Binaries for Python Extension Packages下载了 open cv 二进制文件

Search the page for opencv and for and download the correct .whl for your system.在页面上搜索opencv并为您的系统下载正确的 .whl。 Then pip install it.然后pip安装它。 By example, on my system, after opening a cmd window I typed the following.例如,在我的系统上,打开cmd窗口后,我输入了以下内容。

pip install opencv_python-3.4.1-cp36-cp36m-win_amd64.whl

I then opened python and the following worked然后我打开了python,以下工作

import cv2
print(cv2.__version__)

More info is available in this Mark Jay video .Mark Jay 视频中提供了更多信息。

:D :D

I have tried this several times, but I always get: 我已经尝试了几次,但是我总是得到:

ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none) ERROR: No matching distribution found for opencv-python 错误:找不到满足opencv-python要求的版本(从版本:无)错误:找不到与opencv-python匹配的发行版

Not sure what to do after this. 不知道该怎么办。

@SpeedCoder5's solution applies only to Windows users. @SpeedCoder5 的解决方案仅适用于 Windows 用户。 I am however on macOS (specifically macOS Monterey) and I managed to solve this issue by using the Jupyter Notebook extension in VS Code (Python 3.9) after I installed cv2 with但是,我在 macOS(特别是 macOS Monterey)上,并且在安装 cv2 后,我设法通过在 VS Code(Python 3.9)中使用 Jupyter Notebook 扩展解决了这个问题

pip install opencv-python

jupyter notebook oj vscode截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM