I've developed a python wrapper to a .dll
using ctypes
. I could run the program on two different computers, one with Windows 10 and another with Windows 7. Now I have to run the code on a third computer (I have copied all the files and its structure remains the same), but it throws the following error:
FileNotFoundError: Could not find module 'path_to_dll' (or one of its dependencies). Try using the full path with constructor syntax.
I have created this script to check the .dll
:
from ctypes import CDLL
import logging
import os
try:
lib = CDLL('./eib7_64.dll')
except Exception:
logging.exception("[ERROR]: ")
finally:
print("\nPROGRAM FINISHED")
The complete output is:
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.
I have tried adding this line of code before calling the CDLL:
os.add_dll_directory("C:/Users/User/Desktop/HeidenAndLoadCell/Heiden+LoadCell")
I have also tried to write the full path in the CDLL('path_to_dll')
. In all situations, it throws the same error. The python script and the .dll are inside the same folder. What is the cause of the error?
In the computer where the error is happening:
- Python 3.8.7 64 bits
- Windows 10 64bits (the .dll is also 64 bits)