Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyCharm cannot find cv2 references with the most recent version #20997

Open
1 task
aabramovrepo opened this issue Nov 3, 2021 · 28 comments
Open
1 task

PyCharm cannot find cv2 references with the most recent version #20997

aabramovrepo opened this issue Nov 3, 2021 · 28 comments

Comments

@aabramovrepo
Copy link

  • 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

@alalek
Copy link
Member

alalek commented Nov 3, 2021

duplicate of opencv/opencv-python#574

@asmorkalov
Copy link
Contributor

Related: opencv/opencv-python#570

@bvitaz-ck
Copy link

This is still a problem in version 4.5.5.62

@asenyaev
Copy link
Contributor

asenyaev commented Jan 14, 2022

It has been fixed in opencv/opencv-python#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?

@bvitaz-ck
Copy link

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

@asenyaev
Copy link
Contributor

I've tried to do the same with opencv-contrib-python package and yes, the autocomplete doesn't work, but only for few seconds/minutes. When I'm typing cv. for the first time, the autocomplete shows almost nothing, but when I remove a dot and add it again (sometimes also run a script once), the autocomplete shows anything what I expect. I also remove the cache for it.

@asmorkalov
Copy link
Contributor

It looks like PyCharm builds index for autocomplete for the first several seconds.

@TheBricktop
Copy link

TheBricktop commented Mar 17, 2022

Same in visual studio code : pylance cant see the opencv-contrib modules (some are seen because of the stubgen)

@damonmaria
Copy link

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.

@kaomoneus
Copy link

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.

Confirmed, same here. IDE info:

PyCharm 2021.1.3 (Community Edition)
Build #PC-211.7628.24, built on June 30, 2021
Runtime version: 11.0.11+9-b1341.60 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 11.4

@CDWimmer
Copy link

CDWimmer commented Jul 6, 2022

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.

@1reverseengineer
Copy link

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

@folterj
Copy link

folterj commented Sep 26, 2022

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?

@1reverseengineer
Copy link

1reverseengineer commented Sep 26, 2022

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?

It's not a considerable issue when you take into account the version difference.
From what I remember (about this issue), is that it's more of a PyCharm and pip? issue rather than OpenCV itself.

I have had similar reference issues with other modules in PyCharm which has led me to abandon PyCharm entirely.

@folterj
Copy link

folterj commented Sep 26, 2022

Hi @18iteration if the issue is PyCharm related then totally agreed PyCharm should provide a fix. However considering the previous version had no issue in PyCharm, are you sure this is the case? I've not seen this issue before with other packages in PyCharm, and I've used a LOT of packages. Hopefully this will be fixed in the next release.

@bentennysonyoung
Copy link

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

@folterj
Copy link

folterj commented Nov 28, 2022

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'

@myus3rnam3159
Copy link

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

@cursedgrape
Copy link

will this issue ever be fixed?

@philipperemy
Copy link

philipperemy commented Mar 7, 2023

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

@alexisgaziello
Copy link

This worked for me:
https://stackoverflow.com/a/73087052/7731571

@capt-fuzzy
Copy link

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

you sir, are a saint

@AspirinZJ
Copy link

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. This solved the autocomplete issue but introduced another issue: qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
Do you have any idea how to solve this? Thanks.
image

@damonmaria
Copy link

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

@AspirinZJ
Copy link

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

Thank you. I will give it a try.

@pratikdongre
Copy link

im not able to find cv2 path in my ubuntu system
can someone help me out

@kevleyski
Copy link

kevleyski commented May 27, 2023

Also "Cannot fine declaration" with latest (for me thats v4.7.0.72)

I can see some binary symbols e.g. in site-packages/cv2/cv2.abi3.so, but thats not useful to build skeletons
This didn't work BTW - Settings -> Python Interpreter (show all) -> Show Interpreter Paths (icon)
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/cv2
Reverting to earlier version is not ideal but does work (e.g. 4.5.5.64 seems ok)

When things are workig you'll see files like this:

~/Library/Caches/JetBrains/PyCharm2023.1/python_stubs/.../cv2

by generator 1.147

""" OpenCV Python binary extension loader """

Happy to help fix this, if there are ideas, maybe there was a PyCharm change to 'generator'?

@vitahoang
Copy link

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

worked for me! Thanks a ton 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests