3

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)
Shaido
  • 27,497
  • 23
  • 70
  • 73
  • Try removing the `./` ? – Louis-Justin Tallot Jul 08 '21 at 09:44
  • The *or one of its dependencies* may be relevant, .dll-s can use other .dll files. Probably unrelated, but I would also try from a directory which contains no `+` sign or any other special character in its name – tevemadar Jul 08 '21 at 09:52
  • Thanks for your reply. I have tried it but it raises the same error. – Dimas Avila Martinez Jul 08 '21 at 09:53
  • @tevemadar thanks for your reply. I also thought that the '+' could be an issue. I have tried in other directory but it gives te same error. About the "one of its dependencies" message, when i used the program in other computers never had the error, and i had not any different files. – Dimas Avila Martinez Jul 08 '21 at 09:56
  • See [this answer](https://stackoverflow.com/a/18650202/235698) for help tracking down a dependency, or use the `dumpbin /imports` command. – Mark Tolonen Jul 08 '21 at 15:31
  • 1
    Most likely it's a 3rd-party dependency located in a custom folder. Check your *.dll* using [Dependency Walker](https://www.dependencywalker.com) or (newer) [\[GitHub\]: lucasg/Dependencies](https://github.com/lucasg/Dependencies). – CristiFati Jul 09 '21 at 08:51
  • @CristiFati thanks for you comment. I used Dependency Walker as you suggested and I was able to find the missing .dll. It was a 3rd-party dependency and I could install it with one of the microsoft redistributable for visual studio. The problem is solved. – Dimas Avila Martinez Jul 14 '21 at 07:51

0 Answers0