Discussion:
ImportError: DLL load failed: The specified module could not be found, SWIG, life, etc
Bill Davy
2010-07-05 14:35:59 UTC
Permalink
I am struggling :-(



I have used SWIG to build a module called SHIP. So I have a directory
containing SHIP.py and _SHIP.pyd, as follows:



H:\Viper\HostPC\V1\SHIP\Release>dir

Volume in drive H has no label.

Volume Serial Number is B83B-76F2



Directory of H:\Viper\HostPC\V1\SHIP\Release



05/07/2010 14:43 <DIR> .

05/07/2010 14:43 <DIR> ..

03/07/2010 16:28 41,079 SHIP.py

03/07/2010 14:36 495,616 _SHIP.pyd

2 File(s) 536,695 bytes

2 Dir(s) 58,270,535,680 bytes free







I have a test Python program which imports sys and os and then attempts to
import SHIP; it begins as follows:





## D for John's notebook

## E for Rod's notebook

## H for Bill's notebook

DRIVE = 'H:'



import sys

import os

if ( not os.path.exists(DRIVE) ):

print "Drive \'%s\' does not exist on this machine; edit top of file" %
(DRIVE)

sys.exit(0)



# Prepend our path

sys.path[:0] = [DRIVE + r'\Viper\HostPC\V1\SHIP\Release']



import SHIP



SHIP.Initialise();





I then create a Command Prompt window and enter:





H:\Viper\HostPC\V1\SHIP>C:\Python26\python -vv Test1.py >tmp.txt 2>&1



In tmp.txt, I see the following:



<snipped out lots of importing>

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
on win32

Type "help", "copyright", "credits" or "license" for more information.

# trying H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyd

# trying H:\Viper\HostPC\V1\SHIP\Release\SHIP.py

# H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyc matches
H:\Viper\HostPC\V1\SHIP\Release\SHIP.py

import SHIP # precompiled from H:\Viper\HostPC\V1\SHIP\Release\SHIP.pyc

# trying H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd

# clear[2] __name__

# clear[2] __file__

Traceback (most recent call last):

File "Test1.py", line 15, in <module>

import SHIP

File "H:\Viper\HostPC\V1\SHIP\Release\SHIP.py", line 7, in <module>

import _SHIP

ImportError: DLL load failed: The specified module could not be found.

<snip>



It would seem the "import SHIP" is finding SHIP.py without any trouble.

SHIP.py begins by "import _SHIP".

Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for
some reason, which I cannot fathom, says "DLL load failed".



Can anyone offer me any suggestion where I am going wrong or how to tackle
this problem?



Could it be that the Python 2.6 I am running did not use the same compiler
(VC6) with which I buiult _SHIP.pyd and if so, is there a way round this
without moving on from VC6?



TIA,

Bill
Thomas Jollans
2010-07-05 15:01:28 UTC
Permalink
Post by Bill Davy
I am struggling :-(
smile!
Post by Bill Davy
I have used SWIG to build a module called SHIP. So I have a directory
[ ...]
Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for
some reason, which I cannot fathom, says "DLL load failed".
Maybe it doesn't mean _SHIP.pyd, but another DLL: maybe _SHIP.pyd
depends on some other DLL? Since you used SWIG, I'm guessing that you're
wrapping some other library. Maybe that's what it can't find.
Post by Bill Davy
Can anyone offer me any suggestion where I am going wrong or how to tackle
this problem?
Could it be that the Python 2.6 I am running did not use the same compiler
(VC6) with which I buiult _SHIP.pyd and if so, is there a way round this
without moving on from VC6?
Shouldn't be a problem, as long as the calling convention hasn't change,
which it hasn't. If you're on a 64-bit system there might be a problem
there with Python and some DLLs being built for different architectures?

Cheers,
Thomas
Bill Davy
2010-07-05 17:51:07 UTC
Permalink
"Thomas Jollans" <thomas at jollans.com> wrote in message
Post by Thomas Jollans
Post by Bill Davy
I am struggling :-(
smile!
Post by Bill Davy
I have used SWIG to build a module called SHIP. So I have a directory
[ ...]
Python appears to find H:\Viper\HostPC\V1\SHIP\Release\_SHIP.pyd but for
some reason, which I cannot fathom, says "DLL load failed".
Maybe it doesn't mean _SHIP.pyd, but another DLL: maybe _SHIP.pyd
depends on some other DLL? Since you used SWIG, I'm guessing that you're
wrapping some other library. Maybe that's what it can't find.
Well, there's no mention of another librarary, and "import _SHIP" is the
first (non-comment) statement in SHIP.py
But when I run Dependency Walker against _SHIP.pyd it does say there's a
missing DLL (WINUSB.DLL) so I suspect I've got to sort that out.
Post by Thomas Jollans
Post by Bill Davy
Can anyone offer me any suggestion where I am going wrong or how to tackle
this problem?
Could it be that the Python 2.6 I am running did not use the same compiler
(VC6) with which I buiult _SHIP.pyd and if so, is there a way round this
without moving on from VC6?
Shouldn't be a problem, as long as the calling convention hasn't change,
which it hasn't. If you're on a 64-bit system there might be a problem
there with Python and some DLLs being built for different architectures?
Yep, all for the same architetcure. I suspect it's a dependency problem.
Oh well.
Post by Thomas Jollans
Cheers,
Thomas
Loading...