python filenotfounderror使用模块ctypes和cdll

wtzytmuj  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(1085)

我已经开发了一个python Package 器来 .dll 使用 ctypes . 我可以在两台不同的计算机上运行该程序,一台使用windows 10,另一台使用windows 7。现在我必须在第三台计算机上运行该代码(我复制了所有文件,其结构保持不变),但它会引发以下错误:

FileNotFoundError: Could not find module 'path_to_dll' (or one of its dependencies). Try using the full path with constructor syntax.

我创建此脚本是为了检查 .dll :

from ctypes import CDLL
import logging
import os

try:
    lib = CDLL('./eib7_64.dll')
except Exception:
    logging.exception("[ERROR]: ")
finally:
    print("\nPROGRAM FINISHED")

完整输出为:

ERROR:root:[ERROR]:
Traceback (most recent call last):
  File "checkDLL.py", line 8, in <module>
    lib = CDLL('./eib7_64.dll')
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\ctypes\_init.py", line 373, in __init_
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\User\Desktop\HeidenAndLoadCell\Heiden+LoadCell\eib7_64.dll' (or one of its dependencies). Try using the full path with constructor syntax.

在调用cdll之前,我已尝试添加这行代码:

os.add_dll_directory("C:/Users/User/Desktop/HeidenAndLoadCell/Heiden+LoadCell")

我还尝试在 CDLL('path_to_dll') . 在所有情况下,它都会抛出相同的错误。python脚本和.dll位于同一文件夹中。错误的原因是什么?
在发生错误的计算机中:
python 3.8.7 64位
windows 10 64位(该.dll也是64位)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题