I'm trying to import a module into python but having difficulty.
I have defined the Environment Variable PYTHONPATH which contains C:\MyModules.
I get the following from Python 2.7 when I ask it about the path.
>>> import sys
>>> sys.path
['', 'C:\\MyModules', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']
C:\MyModules contains the module foo.pyd. I know foo.pyd is a working module because it works on other computers.
When I try to import foo, this happens:
>>> import foo
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
ImportError: DLL load failed: The specified module could not be found.
What are the possible reasons this might be happening?
-
1You're most likely missing some third-party dependencies.Russell Dias– Russell Dias2012年01月03日 12:23:28 +00:00Commented Jan 3, 2012 at 12:23
-
As in foo.pyd depends on programs that I do not have installed on my computer?Derek– Derek2012年01月03日 12:25:12 +00:00Commented Jan 3, 2012 at 12:25
-
3Run it through: dependencywalker.comRussell Dias– Russell Dias2012年01月03日 12:25:34 +00:00Commented Jan 3, 2012 at 12:25
-
Thanks, this turned out to be the case. foo.pyd had a third party dependency that was missing. I've added the third party files and it now loads fine. My next question is naturally - Why did python tell me the module could not be found? Why didn't it tell me there was an error loading the module or something more helpful?Derek– Derek2012年01月03日 12:55:54 +00:00Commented Jan 3, 2012 at 12:55
-
I've submitted it as an answer. Hope it helps.Russell Dias– Russell Dias2012年01月03日 13:00:44 +00:00Commented Jan 3, 2012 at 13:00
1 Answer 1
You're missing a dependency, run it through Dependency Walker.
As for your question in the comments. I can only assume the module it was trying to import was written in C, which affected Python's backtrace.
Decided to submit this as an answer.
3 Comments
DLL load failed: was saying that it found the DLL, but loading it failed? And The specified module was the one specified by the DLL, not the one specified by me when I said import foo? That makes more sense. Thanks.