windows Python ctypes.WinDLL 错误,找不到 _dlopen(self._name, mode)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3101981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:42:41  来源:igfitidea点击:

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

pythonwindowsdlldllimportctypes

提问by wizztjh

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.

我该如何解决?我在 中找到了 _dlopen C:\Python26\lib\ctypes\__init__.py,但我真的不知道如何解决它。

采纳答案by Daniel Stutzbach

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:

您可以通过在字符串前放置一个 r 来解决这个问题,这可以防止反斜杠作为转义字符工作:

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")