您的位置:首页 > 其它

ctypes 载入 dll 产生的 WindowsError: [Error 126] 错误原因

2011-01-10 22:28 330 查看
在 Python 里面使用 ctypes 载入 dll 时,如果这个 dll 还依赖于其它的 dll 的话,这些相关的 dll 也得要能被 Python 的进程访问到。如果访问不到就会报以下错误:

>>> import
ctypes

>>> dll = ctypes.WinDLL(r'c:/test/test.dll
')

Traceback (most recent call last):

File "<pyshell#1>", line 1, in <module>

dll = ctypes.WinDLL(r'c:/test/test.dll')

File "D:/Python26/ArcGIS10.0/lib/ctypes/__init__.py", line 353, in __init__

self._handle = _dlopen(self._name, mode)

WindowsError: [Error 126]

>>>

上述例子中,test.dll 依赖于 test_1.dll。单纯的把 test.dll 和 test_1.dll 放在同一个目录下是不行的,因为 Python 进程的起始路径是 “D:/Python26/ArcGIS10.0”,所以它不会到“c:/test/”下去搜索其它的 dll。最好的方法就是在系统环境的 path 里面里面加入 dll 的目录,或者把这些 dll 都一起复制到 Python.exe 所在的目录。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐