0

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?

asked Jan 3, 2012 at 12:19
5
  • 1
    You're most likely missing some third-party dependencies. Commented Jan 3, 2012 at 12:23
  • As in foo.pyd depends on programs that I do not have installed on my computer? Commented Jan 3, 2012 at 12:25
  • 3
    Run it through: dependencywalker.com Commented 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? Commented Jan 3, 2012 at 12:55
  • I've submitted it as an answer. Hope it helps. Commented Jan 3, 2012 at 13:00

1 Answer 1

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.

answered Jan 3, 2012 at 13:00
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, it was written in C++, good guess! I am surprised then that Python doesn't complain that its backtrace didn't work correctly, or something along those lines. It left me wondering why python couldn't find the module.
Don't confuse the python module with the module that is not found - which is the third party dependency module. foo.pyd is found correctly, but complains when loading that foo.pyd can't find the module it depends on.
Okay, so 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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.