How do I diagnose ImportError: DLL load failed when loading native Windows python modules in a virtualenv?

前端 未结 1 406
[愿得一人]
[愿得一人] 2021-01-22 04:34

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

1条回答
  •  一整个雨季
    2021-01-22 04:47

    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\"
    

    0 讨论(0)
提交回复
热议问题