简体   繁体   中英

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.

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'

It was showing import and runtime errors when I typed import cv2 and import numpy in the command prompt.

I tried going back to the previous version of NumPy by typing pip install --force-reinstall numpy=1.19.3 . 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.

I am using Python 3.9.1 with 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. Judging from your screenshots as well as the error, you are running Windows. Try installing Christoph Gohlke's NumPy libraries instead that were built with multicore support enabled.

First do:

pip install pipwin

Then:

pipwin install numpy

This should hopefully settle the OpenCV dependency problem you have.

Instead of doing:

import cv2

try doing:

from cv2 import cv2

This worked for me after a lot of troubleshooting also using pycharm. I now have access to all of the regular cv2 methods.

To solve it, you should upgrade numpy installation. Try:

pip install -U numpy

For information here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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