Extension on Windows

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Fri Nov 19 13:28:37 CET 2010


Eric Frederich wrote:
> I am trying to create an extension on Windows and I may be over my
> head but I have made it pretty far.
> 
> I am trying to create bindings for some libraries which require me to
> use Visual Studio 2005.
> 
> I set up the spammodule example and in VS set the output file to be a .pyd
> file. When I copy that .pyd file into site-packages I can use it just fine
> and call system('dir').

A ".pyd" is a ".dll", just with a different extension. That means that you
can use all tools for DLLs on those, too, like e.g. dependencywalker[1] in
order to check for missing dependent DLLs.

If the name of the PYD is "foo.pyd", Python looks for a function "foo_init"
(or "init_foo") which it calls in order to register the contained code. If
this is missing or has the wrong name, Python won't load it. That means
that you can't rename the file without touching its content!

> Now when I created a 2nd function to wrap a library function I get the
> following.
> 
> ImportError: DLL load failed: The specified module could not be found.

This can mean that the module itself couldn't be loaded or that one of the
DLLs it depends on couldn't be found. Use dependencywalker to check.
 
> I added the correct additional include directories and specified the
> correct .lib file to get it to compile fine without any errors.

That may be so, but it won't make the system pick up the DLL from whichever
location you installed it to.

> What is going on here?  I tried running python with -vvv and got no
> meaningful info... it just fails.

Python tries to load the DLL and only gets told by the system that "the DLL
failed to load", but not which one. I'm afraid Python can't do any better,
since it doesn't have any better info itself.

Uli

[1] http://dependencywalker.com

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list