I'm trying to install OpenCV into my python environment (Windows), and I'm almost all of the way there, but still having some issues with autocomplete and Pycharm itself importing the library. I've been through countless other related threads, but it seems like most of them are either outdated, for prebuilt versions, or unanswered.
I'm using Anaconda and have several environments, and unfortunately installing it through pip install opencv-contrib-python
doesn't include everything I need. So, I've built it from source, and the library itself seem to be working fine. The build process installed some things into ./Anaconda3/envs/cv/Lib/site-packages/cv2/
: __init__.py
, some config py files, and .../cv2/python-3.8/cv2.cp38-win_amd64.pyd
. I'm not sure if it did anything else.
But here's where I'm at:
- In a separate environment, a
pip install opencv-contrib-python
both runs and has autocomplete working - In this environment, OpenCV actually runs just fine, but the autocomplete doesn't work and Pycharm complains about everything, eg:
Cannot find reference 'imread' in '__init__.py'
- Invalidate Caches / Restart doesn't help
- Removing and re-adding the environment doesn't help
- Deleting the user preferences folder for Pycharm doesn't help
- Rebuilding/Installing OpenCV doesn't help
- File->Settings->Project->Project Interpreter is set correctly
- Run->Edit Configuration->Python Interpreter is set correctly
So my question is: how does Pycharm get or generate that autocomplete information? It looks like the pyd file is just a dll in disguise, and looking through the other environment's site-packages/cv2 folder, I don't see anything interesting. I've read that __init__.py has something to do with it, but again the pip version doesn't contain anything (except there's a from .cv2 import *
, but I'm not sure how that factors in). The .whl file you can download is a zip that only contains the same as what 'pip install' gets.
Where does the autocomplete information get stored? Maybe there's some way to copy it from one environment to another? It would get me almost all the way there, which at this point would be good enough I think. Maybe I need to rebuild it with another flag I missed?