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

岁酱吖の 提交于 2020-03-19 05:24:07

问题


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!


回答1:


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.




回答2:


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?




回答3:


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?



来源:https://stackoverflow.com/questions/5667556/pyd-file-fails-to-load-but-dependancywalker-comes-up-clean-and-procmon-shows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!