1

My working code broke after upgrading to Python 3.8.1. Following line used to work, but now returns an error message:

cdll.LoadLibrary('mydllpath/mydll.dll')
==> Could not find module 'mydll.dll'. Try using the full path with constructor syntax.

Someone suggested adding the dll folder to the dll search path. So I changed the code to:

    os.chdir('mydllpath')
    print(os.listdir())  # Proof of success
    os.add_dll_directory('mydllpath')
    cdll.LoadLibrary('my.dll')
    # cdll.LoadLibrary('mydllpath/my.dll')  # Also unsuccessful

Well, the print() on second line of code lists mydll.dll as one of the files in the directory, but Python/cdll still returns the exact same error message: "Could not find ..."
Looking for ideas/suggestions. Thanks ...

Babar-Baig
  • 689
  • 1
  • 12
  • 25
  • Hard to tell what's wrong, but I'd guess that some dependencies are missing since the upgrade. You might have to recompile. If that doesn't work, extract and provide a [mcve] and provide the full (!) error message including the backtrace. – Ulrich Eckhardt Mar 03 '20 at 14:16

1 Answers1

2

OK, I figured-out the issue: Python returned error message: "Could not find module 'mydll.dll'" whether is had a problem locating mydll, or another dll that mydll depends upon. Python 3.8.2 also makes the error message a bit more descriptive.
In my case, mydll.dll depends on a widely used dll located one level-up the directory tree. Once I added that folder to my search path using os.add_dll_directory(), the program started working again.

Babar-Baig
  • 689
  • 1
  • 12
  • 25
  • Did you have problems Python throwing you an AttributeError: module 'os' has no attribute 'add_dll_directory' ? This is what I get when I do os.add_dll_directory(dllpath) - dllpath of course being the main folder where all my driver dlls are – ISquared Nov 04 '20 at 19:01
  • Sorry, that's a new one for me. Idea: Look into the module "os" to make sure the error message is correct. – Babar-Baig Nov 07 '20 at 08:05