Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv autocomplete not working on pycharm

Pycharm doesn't autocomplete my opencv commands. I tried different import commands and some solutions i saw on here but none of them worked and i have to get this project done. Anyone knows how to fix it? I use pycharm community edition 2022.2 and pyhton 3.10.5

pycharm_screenshot

like image 989
deniz Avatar asked Dec 10 '25 06:12

deniz


2 Answers

It's the problem with the opencv version. Opencv version in my environment was upgraded to 4.6.0.66(upgraded when using environment in other projects), then it stopped to autocomplete. The last version I checked to have autocomplete work is 4.5.5.62, so uninstall opencv-python or opencv-contrib-python and install it with version 4.5.5.62!

pip uninstall opencv-python
pip install opencv-python==4.5.5.62
like image 193
artes14 Avatar answered Dec 11 '25 20:12

artes14


Update 4.8 Release fixs this issue.

pip install opencv-python==4.8.0.74.

The following is the old answer.

Workaround:

I got a workaround that works well on Mac and Windows with PyCharm.

Go to the ../site-packages/cv2 and copy the binary file from it to its parent folder.

For Mac OS

Copy ../site-packages/cv2/cv2.abi3.so to ../site-packages/cv2.abi3.so enter image description here

For Windows

Copy ../site-packages/cv2/cv2.pyd to ../site-packages/cv2.pyd enter image description here

And for Ubuntu, we should do the same thing.

NOTE: when your update the opencv-python, don't forget to delete the old abi.so file and copy the new binary to the parent folder.

works out

Restart PyCharm, and wait for the index updating. And everything should work well. And for VS Code, we still can not get the autocomplete for dnn part.

enter image description here

Reference: https://zhuanlan.zhihu.com/p/597733611/preview?comment=0&catalog=0

Further more, agrees with the comment friends: symlinking is a better solution for this issue.

Updated:

Sadly, the issue still exists in the lastest version: I have tested it with opencv-python-4.7.0.68 and opencv-python-4.7.0.72 on my M1 machine.

I have created an issue for it: https://github.com/opencv/opencv-python/issues/821

like image 23
Zihao Mu Avatar answered Dec 11 '25 19:12

Zihao Mu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!