MbedCLI requirements.txt throws error for hidapi

I’ve been trying to utilize mbedcli tools for a project. However everytime I use the command
mbed test
The command runs but I get the following warning:

The Mbed OS tools in this program require the following Python modules: hidapi, cmsis_pack_manager, psutil, cryptography, click, cbor
       You can install all missing modules by running "pip install -r requirements.txt" in "${Workspace-folder}/mbed-os"
       On Mac you might have to install packages as your user by adding the "--user" flag

Doing exactly as it asks, I run:

pip3.7 install -r requirements.txt --user

Resulting in:

error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running bdist_wheel
      running build
      running build_ext
      Compiling hid.pyx because it changed.
      [1/1] Cythonizing hid.pyx
      /private/var/folders/d8/cxmznbcj083czpvyk0ts547h0000gn/T/pip-install-8qb7a_bs/hidapi_af0223a4f48641e9837738a3e4d1f9dd/.eggs/Cython-3.0.11-py3.7-macosx-10.9-x86_64.egg/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /private/var/folders/d8/cxmznbcj083czpvyk0ts547h0000gn/T/pip-install-8qb7a_bs/hidapi_af0223a4f48641e9837738a3e4d1f9dd/hid.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      building 'hid' extension
      error: unknown file type '.pxd' (from 'chid.pxd')
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for hidapi
  Running setup.py clean for hidapi
Failed to build hidapi
ERROR: Could not build wheels for hidapi, which is required to install pyproject.toml-based projects

Any assistance on this would be greatly appreciated.

Hi,

I could reproduce the error on macOS 14.5, python 3.12.3.

To fix this, I installed the latest hidapi module as below with venv.

$ python3 -m venv my_venv
$ source ./my_venv/bin/activate
$ pip3 install --upgrade pip

# edit the requirements.txt to remove restricted version (remove "<0.8.0")
-hidapi>=0.7.99,<0.8.0;platform_system!="Linux"
+hidapi>=0.7.99;platform_system!="Linux"

$ pip3 install -r requirements.txt 
Ignoring pywin32: markers 'platform_system == "Windows"' don't match your environment
Ignoring wmi: markers 'platform_system == "Windows"' don't match your environment

(snip)

Collecting hidapi>=0.7.99 (from -r requirements.txt (line 20))
  Using cached hidapi-0.14.0.post2-cp312-cp312-macosx_11_0_arm64.whl.metadata (3.6 kB)

(snip)

Installing collected packages: wcwidth, pyserial, pyelftools, lockfile, jsonschema, intelhex, idna, colorama, cbor, beautifulsoup4, appdirs, urllib3, six, setuptools, PyYAML, pyusb, pycryptodome, pycparser, psutil, prettytable, MarkupSafe, lxml, future, fasteners, Click, charset-normalizer, certifi, requests, junit-xml, jinja2, hidapi, cffi, milksnake, mbed-os-tools, cryptography, mbed-ls, mbed-host-tests, cmsis-pack-manager, mbed-greentea
Successfully installed Click-7.1.2 MarkupSafe-2.1.5 PyYAML-6.0.2 appdirs-1.4.4 beautifulsoup4-4.6.3 cbor-1.0.0 certifi-2024.7.4 cffi-1.17.0 charset-normalizer-3.3.2 cmsis-pack-manager-0.2.10 colorama-0.3.9 cryptography-3.4.8 fasteners-0.19 future-0.18.3 hidapi-0.14.0.post2 idna-2.7 intelhex-2.3.0 jinja2-3.1.4 jsonschema-2.6.0 junit-xml-1.8 lockfile-0.12.2 lxml-5.2.2 mbed-greentea-1.8.15 mbed-host-tests-1.8.15 mbed-ls-1.8.15 mbed-os-tools-1.8.15 milksnake-0.1.6 prettytable-2.5.0 psutil-5.6.7 pycparser-2.22 pycryptodome-3.20.0 pyelftools-0.28 pyserial-3.4 pyusb-1.2.1 requests-2.32.3 setuptools-72.1.0 six-1.12.0 urllib3-2.2.2 wcwidth-0.2.13

$ pip3 list
Package            Version
------------------ ------------
appdirs            1.4.4
beautifulsoup4     4.6.3
cbor               1.0.0
certifi            2024.7.4
cffi               1.17.0
charset-normalizer 3.3.2
click              7.1.2
cmsis-pack-manager 0.2.10
colorama           0.3.9
cryptography       3.4.8
fasteners          0.19
future             0.18.3
hidapi             0.14.0.post2
idna               2.7
intelhex           2.3.0
Jinja2             3.1.4
jsonschema         2.6.0
junit-xml          1.8
lockfile           0.12.2
lxml               5.2.2
MarkupSafe         2.1.5
mbed-greentea      1.8.15
mbed-host-tests    1.8.15
mbed-ls            1.8.15
mbed-os-tools      1.8.15
milksnake          0.1.6
pip                24.2
prettytable        2.5.0
psutil             5.6.7
pycparser          2.22
pycryptodome       3.20.0
pyelftools         0.28
pyserial           3.4
pyusb              1.2.1
PyYAML             6.0.2
requests           2.32.3
setuptools         72.1.0
six                1.12.0
urllib3            2.2.2
wcwidth            0.2.13
1 Like