Ctypes loading DLL error oserror: [winerror 126] the specified module could not be found

Python calls BaiduFaceApi. DLL

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

Error message:

Traceback (most recent call last):

  File "<ipython-input-12-6f7ace0c1603>", line 1, in <module>
    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 <module>
    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

The reason for the error is that baidufaceapi.dll relies on other DLLS in the X64 folder, but the Python process could not find it.
Solutions:

    modify the current working path:
os.chdir("../x64")

This approach is available in the Base environment of Anaconda, but not in the virtual environment.

    modify the system environment variable PATH, in which absolute PATH “(XXX /x64) “

is added

Read More: