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: Misleading error message upon dependent DLL resolution failure
Type: behavior Stage: resolved
Components: ctypes, Extension Modules, Windows Versions: Python 3.9, Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, miss-islington, paul.moore, plimkilde, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: easy (C), patch

Created on 2020-01-20 09:27 by plimkilde, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18093 merged ZackerySpytz, 2020-01-21 06:44
PR 18230 merged miss-islington, 2020-01-28 09:42
Messages (5)
msg360305 - (view) Author: (plimkilde) Date: 2020-01-20 09:27
Under Windows with Python 3.8+, trying to load a DLL whose dependencies cannot be resolved may produce a misleading error message.

For example, if we are trying to load a library foo.dll that depends on bar.dll, and bar.dll cannot be resolved while foo.dll itself can, Python gives this error message:
"FileNotFoundError: Could not find module 'foo.dll'. Try using the full path with constructor syntax."
(behavior introduced with PR #12302)

Personally, I'd be happy to see a fix that simply adds " (or one of its dependencies)" to the error message.
msg360323 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-01-20 16:20
That clarification seems okay to me. The error message is in load_library in Modules/_ctypes/callproc.c. 

The underlying problem is that the directory of the DLL is only added to the search path (in CDLL.__init__ in Lib/ctypes/ if the caller uses a qualified path. This is an OS limit that we can't avoid.

Also note that the suggestion to use a qualified path won't necessarily resolve the problem, in which case scripts will have to use os.add_dll_directory, and find a reliable way to identify the required directories.
msg360848 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-01-28 09:42
New changeset 13c1c3556f2c12d0be2af890fabfbf44280b845c by Steve Dower (Zackery Spytz) in branch 'master':
bpo-39393: Misleading error message on dependent DLL resolution failure (GH-18093)
msg360851 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-01-28 09:58
Thanks, Zackery!
msg360855 - (view) Author: miss-islington (miss-islington) Date: 2020-01-28 10:00
New changeset 46735c7e101753769e31c69a36d0030bb056a162 by Miss Islington (bot) in branch '3.8':
bpo-39393: Misleading error message on dependent DLL resolution failure (GH-18093)
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83574
2020-05-13 00:02:46eryksunlinkissue40610 superseder
2020-01-28 10:00:20miss-islingtonsetnosy: + miss-islington
messages: + msg360855
2020-01-28 09:58:31steve.dowersetstatus: open -> closed
resolution: fixed
messages: + msg360851

stage: patch review -> resolved
2020-01-28 09:42:55miss-islingtonsetpull_requests: + pull_request17610
2020-01-28 09:42:46steve.dowersetmessages: + msg360848
2020-01-21 06:44:42ZackerySpytzsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request17483
2020-01-20 16:20:30eryksunsetnosy: + eryksun
messages: + msg360323

components: + Extension Modules
keywords: + easy (C)
stage: needs patch
2020-01-20 09:27:30plimkildecreate