OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

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

  • Thread starter Thread starter Neozetare
  • Start date Start date
N

Neozetare

Guest
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:

Code:
$ 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:

Code:
$ 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

Code:
import ctypes
ctypes.CDLL('[my path to the DLL]\\hidapi.dll')
import hid
<p>sorry if the question is not well asked)</p>
<p>I'm trying to use the <a href="https://pypi.org/project/hid/" rel="nofollow noreferrer">Python library hid</a>, which rely on the <a href="https://github.com/libusb/hidapi" rel="nofollow noreferrer">hidapi library</a>. hid seems to not be able to load hidapi, as it's telling me here:</p>
<pre class="lang-sh prettyprint-override"><code>$ 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
</code></pre>
<p>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:</p>
<pre class="lang-sh prettyprint-override"><code>$ 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
</code></pre>
<p>Even if I put it in the folder where I'm running Python from, or in System32, the same error happens again. <a href="https://stackoverflow.com/questions/62620247/how-to-determine-where-to-install-hidapi-dll">This post</a> didn't worked either</p>
<p><strong>EDIT:</strong> 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 (<code>[WinError 193] %1 n’est pas une application Win32 valide</code> 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.</p>
<p>I've found a workaround: manually load the hidapi library before loading the hid library</p>
<pre class="lang-py prettyprint-override"><code>import ctypes
ctypes.CDLL('[my path to the DLL]\\hidapi.dll')
import hid
</code></pre>
 

Latest posts

I
Replies
0
Views
1
Isaac P. Liu
I
U
Replies
0
Views
1
user3658366
U
G
Replies
0
Views
1
Giampaolo Levorato
G
M
Replies
0
Views
1
Marcelo Rodrigo Nascimento
M
Top