[英]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 cv2
和import 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 cv2
和import 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 方法。
can be solved by downgrading opencv https://youtrack.jetbrains.com/issue/PY-35691/Code-completion-doesnt-work-for-cv2-module可以通过降级 opencv https://youtrack.jetbrains.com/issue/PY-35691/Code-completion-doesnt-work-for-cv2-module来解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.