ctypes加载dll报错OSError: [WinError 126] The specified module could not be found

python调用BaiduFaceApi.dll

import ctypes
dllBaiduFaceApi = ctypes.cdll.LoadLibrary("../x64/BaiduFaceApi.dll")

报错信息:

Traceback (most recent call last):

  File "", line 1, in 
    runfile('xxx/main.py', wdir='xxx')

  File "x:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
    execfile(filename, namespace)

  File "x:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "xxx/main.py", line 15, in 
    dllBaiduFaceApi = ctypes.CDLL("../x64/BaiduFaceApi.dll")

  File "x:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)

OSError: [WinError 126] The specified module could not be found

错误的原因在于BaiduFaceApi.dll依赖于x64文件夹中其它dll,但python 进程没有找到。

解决方法:

  1. 修改当前的工作路径:
os.chdir("../x64")

这种方式在anaconda的base环境下可用,但在虚拟环境下不行。

  1. 修改系统环境变量PATH,PATH中添加绝对路径"(xxx/x64)"

你可能感兴趣的:(ctypes加载dll报错OSError: [WinError 126] The specified module could not be found)