Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Troubleshooting DLL imports

In general the error message:

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

Indicates that the python interpreter can not find the library it is looking for. There are a couple steps I take to debug this issue.

Does the path actually exist

Be paranoid and check in the python script that the path actually exists:

import os 
PSSE_PATH = r"C:\Program Files (x86)\PTI\PSSExplore34\PSSPY27" 
if not os.path.exists(PSSE_PATH):    
    print "Bad path"

Is the dll/pyd in the path?

There is a file out there called psspy.dll or psspy.pyd that contains the psspy library. It's like this for any library. Make sure the directory contains the psspy library file. I would just do this on the file system, but lets be paranoid and do it in the script:

# continued from previous script
import glob
fns = glob.glob(os.path.join(PSSE_PATH, 'psspy.*'))
if len(fns) == 0:
   print "Who moved my libraries"

Broken libraries

This is not what is happening to you, but I include it because it is another common class of problems you have when importing a compiled library. You may get an error message which indicates that the library load failed for another reason, like:

ImportError: DLL load failed: %1 is not a valid Win32 application.

In most cases these are caused by a 32/64 bit issue.