opencv: PyCharm cannot find cv2 references with the most recent version

  • OpenCV => 4.5.4.58
  • Operating System / Platform => Ubuntu 18.04.5 LTS
  • Compiler => opencv-python package installed via pip
Detailed description

PyCharm gives the following warning everywhere where cv2.* is used:

cannot find reference <function name> in __init__.py | __init__.py

I’m importing cv2 as:

import cv2

the issue arose with the update to the 4.5.4.58 vesion

Issue submission checklist
  • [ x] I report the issue, it’s not a question
  • [ x] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found solution
  • [ x] I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

any ideas how to overcome this? Thanks!

Best, Alexey

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 12
  • Comments: 28 (5 by maintainers)

Most upvoted comments

It’s the problem with PyCharm, you can remove the warning by add cv2 path into PyCharm’s Interpreter Paths. No need to downgrade opencv-contrib-python. 捕获 捕获2

As above, pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62 gave me a working version but updates past that have broken it again it seems.

It has been fixed in https://github.com/opencv/opencv-python/pull/579.

I’ve tried to reproduce using the latest version - 4.5.5.62, but it works on my side. I’ve even tried to clean cache.

My steps to reproduce:

  1. Install opencv-python with the latest version and use several flags.
python3 -m pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62
  1. Try to find several functions in PyCharm. image

Tried the same using File -> Invalidate Caches / Restart… in PyCharm.

@bvitaz-ck, could you tell me what I am doing wrong or different?

PyCharm was working for me with opencv-python but stopped working again when I upgraded to 4.6. Downgrading back to 4.5.5.64 solves it.

pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62

I can confirm this works absolutely brilliantly with opencv-contrib-python. Pycharm refused to index or autocomplete properly while on OpenCV version 4.6 (both main and contrib).

Running the above mentioned command fixed it immediately after Pycharm was done rebuilding skeletons and Indexing. Thank you @CDWimmer

It’s the problem with PyCharm, you can remove the warning by add cv2 path into PyCharm’s Interpreter Paths. No need to downgrade opencv-contrib-python. 捕获 捕获2

Thank you very much

With all due respect, downgrading is a work-around, not a solution - and certainly not long term. Dear OpenCV team, assuming this issue is related to the python OpenCV package, can this be solved please?

This seems a reasonable solution, thank you very much for this @bentennysonyoung!

Just a comment on the screenshots - the top image shows 1: ‘Project’->‘Python interpreter’ 3: ‘Show all’

The bottom image shows after adding the cv2 path: 3: … (added by user) 4: ‘Ok’

As an alternate to adding the cv2 path into the interpreter, symlink the cv2/cv2.abi3.so file (cv2.pyd in WIndows?) into the site-packages dir. For example, in site-packages: ln -s cv2/cv2.abi3.so

Install the latest Pycharm and downgrade the CV lib to 4.5.X. Something like that should work:

pip install opencv-python==4.5.5.62

Ref: https://stackoverflow.com/a/73057619/4170095

will this issue ever be fixed?

After some experimentation, opencv-python appears to work, but opencv-contrib-python does not.