Does this PYD file have dependencies – be them other PYDs, DLLs or Python libraries? This should be as simple as adding the parent directory to sys.path
and running import sd
so if there’s no dependencies at play here, I’d be surprised if you hadn’t got that working. The fact that you’re getting a DLL load failed
error instead of a ModuleNotFoundError
would also imply that your PYD is findable but not loadable.
I have tried manually setting the PATH and PYTHONPATH in the console and even copying the .pyd file to be alongside the .exe itself, but nothing works. Now the weird part. If I re-run the pyInstaller build with my PYTHONPATH set to the location where my .pyd file resides, it creates an executable that does work. So it appears that pyInstaller has its own notion of a PYTHONPATH that can be augmented at build time but not runtime??
This also suggests the same. I think PyInstaller sees that import sd
, includes the PYD then runs it through its binary dependency analysis where it discovers whatever DLLs this PYD is linked against and collects them.
P.S. That __get_run_path()
path function is redundant. You should use os.path.abspath(os.path.dirname(__file__))
unconditionally – adjusting any --add-data
arguments so that the files are put where the code now expects them to be.