Extension on Windows

E

Eric Frederich

Hello,

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').

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.

I added the correct additional include directories and specified the
correct .lib file to get it to compile fine without any errors.

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

What else do I need to do?

Thanks,
~Eric
 
U

Ulrich Eckhardt

Eric said:
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
 
E

Eric Frederich

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.

What do I do when I find these dependencies?
Do I put them in some environment variable?
Do I put them in site-packages along with the .pyd file, or in some
other directory?
 
U

Ulrich Eckhardt

Eric said:
Do I put them [DLL dependencies] in some environment variable?
Do I put them in site-packages along with the .pyd file, or in some
other directory?

Take a look at the LoadLibrary() docs:
http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx

These further lead on to:
http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx
which details in what order different places are searched for DLLs.

If you put the DLL in the same directory as your PYD, it should work. This
is not the most elegant solution though, see above for more info.

Cheers!

Uli
 
E

Eric Frederich

Eric said:
Do I put them [DLL dependencies] in some environment variable?
Do I put them in site-packages along with the .pyd file, or in some
other directory?

Take a look at the LoadLibrary() docs:
 http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx

These further lead on to:
 http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx
which details in what order different places are searched for DLLs.

If you put the DLL in the same directory as your PYD, it should work. This
is not the most elegant solution though, see above for more info.

Well... I used the tool and found missing dependencies and just copied
them into site-packages.
There were two. Then when I put those two in there and ran
dependencywalker again, I had 6 more missing.
I found all of these dependencies in a "bin" directory of the program
which I'm trying to create bindings for.
The one I couldn't find was MSVCR80.DLL but my python module imported
fine so maybe its not a big deal (actually, if I throw one of their
dll files into dependency walker it shows the same thing).
This was just with me wrapping one (very basic) routine. I would
imagine as I wrap more and more, I'd need more and more dll files.

I think rather than copying .dll files around, I'll just put my .pyd
file in their 'bin' directory and set PYTHONPATH environment variable.

Things are starting to look promising.

I now have to deal with other issues (coming up in a new python-list thread).

Thanks a bunch Ulri.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top