简体   繁体   中英

Can't load hidapi with Python library "hid" on Windows

sorry if the question is not well asked)

I'm trying to use the Python library hid , which rely on the hidapi library . hid seems to not be able to load hidapi, as it's telling me here:

$ python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]\Python310\site-packages\hid\__init__.py", line 30, in <module>
    raise ImportError(error)
ImportError: Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll

The problem is that I have downloaded one of those libraries from hidapi's release page (the Windows x64 version), but it doesn't seem to matter where I put it, it doesn't work. It is in my PATH:

$ echo $PATH
[...]:/c/Program Files/hidapi:[...]

$ ls -lh "/c/Program Files/hidapi"
total 3.0M
-rwxr-xr-x 1 [...] 197121  98K Jan 28 14:38 hidapi.dll*
-rw-r--r-- 1 [...] 197121 5.7K Jan 28 14:38 hidapi.lib
-rw-r--r-- 1 [...] 197121 2.9M Jan 28 14:38 hidapi.pdb

Even if I put it in the folder where I'm running Python from, or in System32, the same error happens again. This post didn't worked either

EDIT: I didn't solve the core problem, but the ctypes library that is trying to load the library isn't skiping it because it can't find it but because it isn't a valid Win32 app ( [WinError 193] %1 n'est pas une application Win32 valide is the error, in french though). Maybe it is be cause it's not registered, but I'm not sucessful at trying to register it.

I've found a workaround: manually load the hidapi library before loading the hid library

import ctypes
ctypes.CDLL('[my path to the DLL]\\hidapi.dll')
import hid

I put hidapi.dll and hidapi.lib in C:\Users\<Username>\AppData\Local\Programs\Python\Python310 and it worked: :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM