Reputation: 461
I recently compiled the OpenCV 4.4.0
with CUDA
and Python3
bindings following this instruction. I install it to a virtualenv in Anaconda, and it works in Anaconda Prompt. But as I want to use it in Pycharm
, the code import cv2
is underlined with the hint (just underlined, not run yet):
No module named cv2
Even though I could import errorless and use it anyway. And then there's no "hint info" as my cursor was on the code e.g. cv2.imread()
(normally there would be hints about input name and format etc.). So the problem should just be that Pycharm couldn't recognize it.
Could anyone enlighten me a little? Thanks!
Upvotes: 3
Views: 180
Reputation: 461
Emmm I've solved it myself in a stupid way.
Since the problem is we only have the .pyd
binding file, we need to make it a python package with reference files in it, like what we'd get from a normal cv2 module from pip install
. So I just:
pip install opencv-python=4.4.0.42
(or another version you desire).pyd
file to the target virtual env. In my case it's located in [PathToAnacondaEnvs]\MoVis_gpu\Lib\site-packages\cv2\
, so that __init__.py
will make cv2 as a legitimate python package, and other files would add reference for it.Not elegant, but it works :)
Upvotes: 1