简体   繁体   English

安装 opencv 后,如何解决 python 中的“Cannot find reference 'imread' in '__init__.py”错误?

[英]How to resolve this error of "Cannot find reference 'imread' in '__init__.py" in python after installing opencv?

I am new to python and installed opencv by typing: pip install opencv-contrib-python in the command prompt.我是 python 的新手,并通过在命令提示符下键入: pip install opencv-contrib-python安装了 opencv。

Below I have shown a very simple example of reading in an image and showing it on the screen:下面我展示了一个非常简单的读取图像并将其显示在屏幕上的示例:

在此处输入图像描述

However, I get this error:但是,我收到此错误:

在此处输入图像描述

When I hover over the imread method in PyCharm, it says Cannot find reference 'imread' in '__init__.py'当我通过 PyCharm 中的imread方法进行 hover 时,它Cannot find reference 'imread' in '__init__.py'

It was showing import and runtime errors when I typed import cv2 and import numpy in the command prompt.当我在命令提示符下键入import cv2import numpy时,它显示导入和运行时错误。

I tried going back to the previous version of NumPy by typing pip install --force-reinstall numpy=1.19.3 .我尝试通过键入pip install --force-reinstall numpy=1.19.3返回到 NumPy 的先前版本。 So, now when I type import cv2 and import numpy in the command prompt, it shows no error but it says it still can't find a reference to it in PyCharm.所以,现在当我在命令提示符下键入import cv2import numpy时,它没有显示错误,但它说它仍然无法在 PyCharm 中找到对它的引用。

I am using Python 3.9.1 with pip 20.2.3.我正在使用 Python 3.9.1 和 pip 20.2.3。

The NumPy multicore import error is a result of installing NumPy on Windows that is incompatible with the version of OpenCV that you have. The NumPy multicore import error is a result of installing NumPy on Windows that is incompatible with the version of OpenCV that you have. Judging from your screenshots as well as the error, you are running Windows.从您的屏幕截图和错误来看,您正在运行 Windows。 Try installing Christoph Gohlke's NumPy libraries instead that were built with multicore support enabled.尝试安装 Christoph Gohlke 的 NumPy 库,而不是在启用多核支持的情况下构建。

First do:首先做:

pip install pipwin

Then:然后:

pipwin install numpy

This should hopefully settle the OpenCV dependency problem you have.这应该有望解决您遇到的 OpenCV 依赖问题。

Instead of doing:而不是这样做:

import cv2

try doing:尝试做:

from cv2 import cv2

This worked for me after a lot of troubleshooting also using pycharm.在使用 pycharm 进行大量故障排除后,这对我有用。 I now have access to all of the regular cv2 methods.我现在可以访问所有常规的 cv2 方法。

To solve it, you should upgrade numpy installation.要解决它,您应该升级 numpy 安装。 Try:尝试:

pip install -U numpy

For information here此处获取信息

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

相关问题 Python 3 Opencv 设置问题:“在 __init__.py 中找不到引用‘VideoCapture’” on Pycharm IDE - Python 3 Opencv set up problem: "cannot find reference 'VideoCapture' in __init__.py" on Pycharm IDE 在“__init__.py”中找不到参考“TextVectorization” - Cannot find reference 'TextVectorization' in '__init__.py' 在 __init__.py 中找不到引用“xxx” - Cannot find reference 'xxx' in __init__.py 在 __init__.py [暂停] 中找不到引用“ref_name” - Cannot find reference 'ref_name' in __init__.py [on hold] 为什么 pygame 在“__init__.py”中找不到引用“...”? - Why pygame cannot find reference '…' in '__init__.py'? PyCharm 在 __init__.py 中找不到任何 OpenCV function 的参考 - PyCharm can´t find reference of any OpenCV function in __init__.py Tensorflow 可以在 Pycharm 中使用,但在 __init__.py 中找不到引用 `xxx` - Tensorflow can be used in Pycharm, but cannot find reference `xxx` in __init__.py 在“ __init __。py” Google自定义搜索API中找不到引用“发现” - Cannot find reference 'discovery' in '__init__.py' Google custom search API Python OpenCV 的基本命令“Cannot find reference in '__init__'.py - Python OpenCV's basic commands "Cannot find reference in '__init__'.py 导入错误:在__init__.py中明确声明后无法导入function - Import Error: Cannot import function after clearly declaring in the __init__.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM