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

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
pip install opencv-python==4.8.0.74.
The following is the old answer.
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.
Copy ../site-packages/cv2/cv2.abi3.so to ../site-packages/cv2.abi3.so

Copy ../site-packages/cv2/cv2.pyd to ../site-packages/cv2.pyd

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.
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.

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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With