How to install a hidapi (python module) to a particular Python instance?

68 Views Asked by At

Python Setup:

My iMac's Default python is configured for 3.10.8:

user@iMac ~ % python3 -V
Python 3.10.8
user@iMac ~ % which python3
/usr/local/bin/python3
user@iMac ~ % 
user@iMac ~ % ls -l /usr/local/bin/python3
lrwxr-xr-x  1 root  wheel  70 Oct 11  2022 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3
user@iMac ~ % 
user@iMac ~ % brew list | grep -i python
python-setuptools
[email protected]
[email protected]
mysql-connector-python

user@iMac ~ % brew list hidapi
/usr/local/Cellar/hidapi/0.14.0/bin/hidtest
/usr/local/Cellar/hidapi/0.14.0/include/hidapi/ (2 files)
/usr/local/Cellar/hidapi/0.14.0/lib/libhidapi.0.14.0.dylib
/usr/local/Cellar/hidapi/0.14.0/lib/cmake/ (4 files)
/usr/local/Cellar/hidapi/0.14.0/lib/pkgconfig/hidapi.pc
/usr/local/Cellar/hidapi/0.14.0/lib/ (2 other files)

hidapi was installed via brew install hidapi and was installed to python3.11:

user@iMac ~ % pip show hid
Name: hid
Version: 1.0.5
Summary: ctypes bindings for hidapi
Home-page: https://github.com/apmorton/pyhidapi
Author: Austin Morton
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.11/site-packages

Symptom

import hid fails

user@iMac ~ % brew list hidapi

/usr/local/Cellar/hidapi/0.14.0/bin/hidtest
/usr/local/Cellar/hidapi/0.14.0/include/hidapi/ (2 files)
/usr/local/Cellar/hidapi/0.14.0/lib/libhidapi.0.14.0.dylib
/usr/local/Cellar/hidapi/0.14.0/lib/cmake/ (4 files)
/usr/local/Cellar/hidapi/0.14.0/lib/pkgconfig/hidapi.pc
/usr/local/Cellar/hidapi/0.14.0/lib/ (2 other files)
user@iMac ~ % python3
Python 3.10.8 (v3.10.8:aaaf517424, Oct 11 2022, 10:14:40) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import hid

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/Library/Python/3.10/lib/python/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

Goal

hidapi is installed for 3.10.8

Question

What is the process / command for install hidapi for 3.10.8 and avoid the symptom?

python3 -m pip install hidapi

user@iMac ~ % brew uninsatll hidapi. #remove hidapi via brew

Error: Unknown command: uninsatll
user@iMac ~ % brew uninstall hidapi
Uninstalling /usr/local/Cellar/hidapi/0.14.0... (19 files, 172.6KB)

user@iMac ~ % brew list hidapi #confirm brew has removed hidapi

Error: No such keg: /usr/local/Cellar/hidapi

user@iMac ~ % python3 -m pip install hidapi #install hidapi via default python

**Defaulting to user installation because normal site-packages is not writeable**
Requirement already satisfied: hidapi in ./Library/Python/3.10/lib/python/site-packages (0.14.0)
Requirement already satisfied: setuptools>=19.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from hidapi) (63.2.0)
user@iMac ~ % python3
Python 3.10.8 (v3.10.8:aaaf517424, Oct 11 2022, 10:14:40) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import hid

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/Library/Python/3.10/lib/python/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
0

There are 0 best solutions below