其实我遇上的错误是dll名字弄错了,就出现126错误了。

 

 

转自:http://hi.baidu.com/drunkdream/item/e0d24a0a26f7cf19ebfe38c1

在 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 所在的目录。