I am using Python 3.x and a virtualenv -- not conda, just a plain virtualenv.
I activate the venv and run pip install opencv-python
. However,
import cv2
On resolving "module could not be found" errors in general
Try using either Microsoft's Dependency Walker or lucasg's Dependencies on the module being loaded. Be sure to run Dependencies.exe from your virtualenv's command prompt, so it picks up your modified PATH.
The import line is from .cv2 import *
, so the module being loaded is in the same directory as __init__.py
(this is the leading .
) and named cv2-SOMETHING.pyd
(this is what native Python modules look like). Load that file into Dependencies.exe and it will show you the DLL that Windows wants but can't find.
In this case, the DLL is Python3.dll. Why is it missing? Because of a virtualenv bug that is fixed, but hasn't made its way into a release -- there hasn't been a release in more than a year.
On resolving this issue in particular
The github issue suggests a fix: use venv.
Alternatively you can copy the missing python3.dll
into your virtualenv by hand. You'll have to do this for every virtualenv you create.
copy "c:\Program Files\Python36\python3.dll" "c:\src\venv\tf\Scripts\"