'Can't find DLL with PyInstaller on one PC but can on another

Preamble

I've built a Flask app (with Python, obviously) that interacts via ctypes with a DLL that I've coded in C. This works perfectly.

Then I used PyInstaller to package it up, adding --add-binary ..\build\my.dll;build to the PyInstaller invocation. (I'm using the one-directory approach, not one-file.)

This works fine. The final executable runs perfectly, just like the original Python version.

Problem

The tricky part is that it doesn't work on another PC. It reports:

_main__.PyInstallerImportError: Failed to load dynlib/dll '\\path\\to\\build\\my.dll'. Most probably this dynlib/dll was not found when the application was frozen.

The reported path is correct. And I even asked Python to list the contents of the directory immediately before trying to load the DLL, and it's there.

The (successful) primary PC and the (failing) test PC are both 64-bit Windows, and the DLL is 64-bit.

I'm at a bit of a loss. I've tried using --hidden-exports too, but I think that's redundant with the explicit --add-binary. I've tried making it fail on the primary PC by starting a new console and running from there (in case I'd set some paths up but forgotten, or there was something magic in my venv, but it stubbornly works ever time!).

Help me, SO, what have I missed?



Solution 1:[1]

@MarkTolonen pointed me in the right direction:

Use Sysinternals Process Monitor. Configure it to monitor the python.exe process for CreateFile operations:

What I learned from this is that my C DLL was referencing another DLL, and that was not found on the test PC. (I thought I had statically linked all the code I needed into my DLL, but it turns out that I'd just linked with the stub library for the other DLL.)

I guess the important detail is that the error message said "failed to load", not "failed to find". I was fixated on it meaning the latter.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Edd Inglis