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 所在的目录。
>>> 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 所在的目录。
相关文章推荐
- ctypes 载入 dll 产生的 WindowsError: [Error 126] 错误原因
- 关于安装.NET Framework 2.0时偶然碰到的问题(提示"Error 205015. 安装程序集..../System.EnterpriseServices.dll失败,原因是出现了系统错误:拒绝访问。")
- 错误信息:CFNetwork internal error 及产生原因
- 如何解决加载动态链接库DLL失败,返回0,GetLastError返回错误码126
- Linux系统内存错误产生的原因及调试方法(段错误|core dumped)
- 使用mybatis 产生Invalid bound statement (not found)错误原因
- 出现java.lang.UnsupportedClassVersionError 错误的原因
- C# Maximum request length exceeded. 产生错误的原因,以及解决方法.
- 出现java.lang.UnsupportedClassVersionError 错误的原因
- [转]WebService 中Maximum request length exceeded. 产生错误的原因,以及解决方法.
- error while loading shared libraries: xxx.so.x"错误的原因和解决办法
- error while loading shared libraries: xxx.so.x" 错误的原因和解决办法
- "error while loading shared libraries: xxx.so.x" 错误的原因和解决办法
- 如何解决导出DBF时“字段将不能置于记录中”错误?记录过大错误产生原因
- 剖析java.lang.OutOfMemoryError: Java heap space产生原因及解决方法
- "error while loading shared libraries: xxx.so.x" 错误的原因和解决办法
- error while loading shared libraries: xxx.so.x"错误的原因和解决办法 [转]
- Linux环境下段错误的产生原因及调试方法小结
- “Error:ShouldNotReachHere()”错误的原因
- zookeeper错误:KeeperErrorCode = NoChildrenForEphemerals的原因