Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python ctypes.WinDLL error , _dlopen(self._name, mode) can't be found

ctypes.WinDLL("C:\Program Files\AHSDK\bin\ahscript.dll")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

How can I solve it? I found the _dlopen in C:\Python26\lib\ctypes\__init__.py, but I really don't know how to solve it.

like image 335
wizztjh Avatar asked Jun 23 '10 13:06

wizztjh


1 Answers

Backslashes are an escape character within strings, as demonstrated in the example below:

>>> print "C:\Program Files\AHSDK\bin\ahscript.dll"
C:\Program Files\AHSDinhscript.dll

You can solve the problem by placing an r before the string, which prevents the backslash from working as an escape character:

ctypes.WinDLL(r"C:\Program Files\AHSDK\bin\ahscript.dll")

Alternately, you could escape the backslashes:

ctypes.WinDLL("C:\\Program Files\\AHSDK\\bin\\ahscript.dll")
like image 167
Daniel Stutzbach Avatar answered Oct 22 '22 13:10

Daniel Stutzbach