当我看到类似这样的信息时-通常是因为路径中存在反斜杠,这些反斜杠会被转换。
例如-以下操作将失败-因为字符串中的 t转换为TAB字符。
>>> import ctypes>>> ctypes.windll.LoadLibrary("c:toolsdependsdepends.dll")Traceback (most recent call last): File "<stdin>", line 1, in <module> File "c:toolspython271libctypes__init__.py", line 431, in LoadLibrary return self._dlltype(name) File "c:toolspython271libctypes__init__.py", line 353, in __init__ self._handle = _dlopen(self._name, mode)WindowsError: [Error 126] The specified module could not be found有3个解决方案(如果这是问题)
a)使用双斜杠…
>>> import ctypes>>> ctypes.windll.LoadLibrary("c:\tools\depends\depends.dll")b)使用正斜杠
>>> import ctypes>>> ctypes.windll.LoadLibrary("c:/tools/depends/depends.dll")c)使用RAW字符串(以r开头的字符串
>>> import ctypes>>> ctypes.windll.LoadLibrary(r"c:toolsdependsdepends.dll")
尽管这第三个方法有效-
我不时地感到它不被认为是“正确的”,因为RAW字符串是用于正则表达式的。多年来我一直在使用Windows在Python中的路径上使用它,没有问题:))


![WindowsError:[错误126]找不到指定的模块 WindowsError:[错误126]找不到指定的模块](http://www.mshxw.com/aiimages/31/660009.png)
