This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: ctypes on Windows: error message on DLL load failure is misleading
Type: enhancement Stage: resolved
Components: ctypes Versions: Python 3.8
Status: closed Resolution: duplicate
Dependencies: Superseder: Misleading error message upon dependent DLL resolution failure
View: 39393
Assigned To: Nosy List: eryksun, jackjansen
Priority: normal Keywords:

Created on 2020-05-12 23:04 by jackjansen, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg368748 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2020-05-12 23:04
On Windows, when ctypes fails to load a DLL, the error message is misleading. If a dependency of the DLL cannot be found if appears as if the DLL itself cannot be found.

This issue has always existed on Windows (and I know it is due to what the OS provides by default as its error message) but it is exacerbated by the DLL loading rules in Python 3.8 (the `os.add_dll_directory()` changes), because now importing a DLL into Python will follow different rules than those followed by, for example, command line utilities shipped with the DLL you are loading follow.

An ideal fix would be a message of the form "xxx.dll failed to load because its dependency yyy.dll is not on the current Python DLL search path, see zzzz for details". But I am not well-versed enough in Windows APIs to know whether that is even possible.

A fix that is minimal and at least not misleading would be a message "xxx.dll (or one of its dependencies) failed to load. See zzzz for details".
msg368751 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-05-13 00:02
bpo-39393 improved the error message to mention "(or one of its dependencies)". That's the best we can reasonably do. A developer can monitor "loader snaps" messages in a debugger in order to discover the missing DLL and the directories where the loader looked for it.
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84790
2020-05-13 00:02:46eryksunsetstatus: open -> closed

superseder: Misleading error message upon dependent DLL resolution failure

nosy: + eryksun
messages: + msg368751
resolution: duplicate
stage: resolved
2020-05-12 23:04:27jackjansencreate