*.pyd file fails to load, but DependancyWalker comes up clean, and ProcMon shows it loaded
Asked Answered
P

3

5

I am trying to load a *.pyd with Python, but I receive the well known "Import Error: DLL load failed: the specified procedure can not be found." error.

I have already done the following:

1.) Investigated the *.pyd with Dependency Walker. GPSVC.DLL and IESHIMS.DLL came up as missing, but delay loaded, IEFRAME.DLL aslo came up as missing an export, but was also delay-loaded. It's my understanding that these are not used, and are delay load anyway, so they should not be the problem.

2.) Did an "import foo" on foo.pyd in the python command window, with ProcMon watching. ProcMon shows event "LoadImage" on "foo.pyd" with result SUCCESS.

This seems to imply that the *.pyd file loaded correctly.

So what am I missing. My windows diagnostics are telling me all is well, but python is telling me the thing cannot be loaded (usually due to a missing dll or symbol).

Ideas?

Thanks!

Pneumonectomy answered 14/4, 2011 at 18:5 Comment(2)
UPDATE: I built a small program to do a LoadLibrary() on the *.pyd in question. The output shows that the *.pyd loaded properly, and it's dependencies (which without the *.pyd would not be needed by the program) were also picked up and loaded properly.Pneumonectomy
For future reference: Dependency Walker is outdated now, it's preferably to use Dependencies: github.com/lucasg/DependenciesAarau
J
5

Is the .pyd file for the same version of Python you're using? Loading a .pyd file for the wrong Python version can produce that error message.

Dependency Walker can show you which pythonNN.dll it links to.

Jermaine answered 14/4, 2011 at 20:7 Comment(2)
It seems to be the same version. All documentation states it works with Python 2.6, which is what I am using. And Dependency Walker also shows it linked to Python26.dllPneumonectomy
Different versions of python26.dll. That was the issue.Pneumonectomy
P
2

Ok here is the answer:

The windows diagnostics (depends, procmon, etc) were showing the DLL (or pyd) loading fine.

Python was showing that it was not loading fine.

I found that the windows tools were referring to a different Python26.dll hiding in my C:\Window\SysWOW64 folder.

This second Python26.dll (found in SysWOW64) has a symbol that is missing in the primary python26.dll (installed by the windows python installer, found in C:\Python26).

This symbol "_PyByteArray_empty_string", was apparently needed by my *.pyd file.

So when loading via windows diagnostics, the SysWOW64 dll was found, and the *.pyd loaded properly. When loading from python, the dll in C:\Python26\ was found, the symbol was missing, and load failed.

So that is WHY the problem manifested. The question now is: Why are there two versions of Python26.dll floating around, one with _PyByteArray_empty_string, and one without?

I'm using Python 2.6.6. Perhaps this symbol is removed in 2.6.6 but present in some older 2.6.x release?

Pneumonectomy answered 16/4, 2011 at 14:21 Comment(0)
L
1

If you have a file foo.pyd, for import foo to succeed, there must be an externally accessible function named initfoo. Dependency Walker will show this (typically the ONLY function) if it exists. initfoo needs to be called by Python to initialise the foo module.

Note: I would expect a more explicit error message if this were the problem:

>>> import fubar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initfubar)
>>>

You say that you are "trying to load a *.pyd file". Is that just a strange way of describing import foo or is it something else?

Did you create the pyd? If not, who did? Have you asked them? Is this pyd available on the web so that others could try to load/import it?

Lewan answered 14/4, 2011 at 23:29 Comment(2)
Another possibility is that one of the missing "delay-load" DLLs actually is needed by the init function.Loosejointed
Thank you for your input. The *.pyd does define initfoo properly, this is the ONLY function in the *.pyd (as you describe). The error message is not more explicit, indicating that the failure is down in the Windows dll loading system where python cannot tell where the load failure occurred.Pneumonectomy

© 2022 - 2024 — McMap. All rights reserved.