Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find which DLL failed in "ImportError: DLL load failed while importing" in python?

Context

Are there commands to enhance the error message that is received such that python displays which .dll file it cannot find?

For error:

python test_cv2.py
Traceback (most recent call last):
  File "test_cv2.py", line 1, in <module>
    import cv2
  File "E:\Anaconda3\envs\py38\lib\site-packages\cv2\__init__.py", line 5, in <module>
    from .cv2 import *
ImportError: DLL load failed while importing cv2: The specified module could not be found.

(py38) E:\somepath>

I would like to determine which .dll file is actually not being found. To do so, I downloaded and run DependenciesGui.exe from this repository.. Next I fed the DependenciesGui.exe the cv2.cp38-win_amd64.pyd which indicates api-ms-win-core-wow64-l1-1-1.dll is missing, amongst others.

I currently do not have a way to verify that the .dll files that are reported missing by dependenciesGUI.exe are also the files that python 3.8 is not finding in the anaconda environment.

A way to implicitly verify that the python 3.8 missing .dll files are the same as the same files reported missing by dependenciesGUI.exe would be to download and paste all the missing .dll files into ../system32/. Followed by inspecting if the error message dissapears/changes. However one of the .dll files reported missing is: api-ms-win-core-wow64-l1-1-1.dll which I am not yet able to find (online). Also I tried to cheat to copy and rename api-ms-win-core-wow64-l1-1-0.dll to api-ms-win-core-wow64-l1-1-1.dll but that (luckily) doesn't enable the dpendenciesGUI.exe to recognize the .dll file as found.

Question

How can I make the error message/traceback of python explicitly mention which .dll file is (the first .dll file that is) not found?

Note

This is not about solving the xy-problem of installing opencv.

like image 422
a.t. Avatar asked Jul 04 '20 17:07

a.t.


1 Answers

Short answer: No.

Although it is probably not completely impossible, it would require to bind a tool like dependenciesGUI in Python, in order to be able to call it in that given context (namely taking into account the actually search path for dll in Python and already loaded dynamics libraries). It would be quite a lot of work for little gain. Indeed, the default search path in Python>=3.8 on Windows should be very similar to the one of dependenciesGUI, so that the missing dll should be the same. Personally, I'm developing pre-compiled binary distributions for Python, and so far dependenciesGUI was enough to identify the missing libraries at Python import.

like image 194
milembar Avatar answered Sep 21 '22 19:09

milembar