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

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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值