You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.
Seems that on Python 3.8+ searching for DLLs is done a bit differently. Prior Python 3.8 you could just add DLL folder to Process PATH and DLL's would be loaded.
PATH and current working directory are not used in Python 3.8+.
New function called os.add_dll_directory was added in Python 3.8. It adds a path to DLL search path. It is used when resolving dependencies for imported extension modules and by ctypes.
Python 3.8 and usb.backend.libusb1._load_library()
It means, even with the DLL folder added with os.add_dll_directory and that same folder in the PATH the pyusb libusb1._load_library() does not seem to find the dll.
It seems that the problem was that I tried to add 64-bit libusb-1.0.dll using 32-bit Python 3.8.
The usb.backend.libusb1._load_library() started working by just adding the 32-bit libusb-1.0.dll to the PATH with pathtub.ensure. However, in Python 3.8, one should
Add DLLs folders with os.add_dll_directory, as this is the official "new way".
Add the folder also to the Process PATH, since some python packages (like this pyusb, for example) might have their own ways of finding the dlls, which rely on the PATH.
frompathtubimportensure_dllensure_dll(r'C:\path to my favourite\dlls')
there is also a function forget_dll to forget added dll folder (even though they are just added for the process, sometimes this might be needed)
Why not just use ensure() for DLLs?
The reason for not using pathtub.ensure for ensuring that python (and other DLLs) find DLLs is that the ensure is used to ensure that a folder is found in PATH, and it is completely different task than ensuring DLLs to be found. Also, the ensure has for example parameter permanent, which at least for now would be difficult to implement in every DLL case.
Steps to reproduce
Expected behaviour
usb.backend.libusb1._load_library()
returns without ExceptionsActual behaviour
usb.backend.libusb1._load_library()
throwsLibraryNotLoadedException
The text was updated successfully, but these errors were encountered: