运行setup.sh时无法构建hidapi wheel的解决方法问询
安装CoralMicro依赖时hidapi构建wheel失败的问题
运行bash setup.sh安装CoralMicro依赖时,遇到hidapi无法构建wheel的错误,提示error: unknown file type '.pxd' (from 'chid.pxd'),多次执行setup.sh仍无法解决。完整报错日志如下:
coralmicro % bash setup.sh ==> Downloading https://formulae.brew.sh/api/cask.jws.json ######################################################################### 100.0% Warning: Treating cmake as a formula. For the cask, use homebrew/cask/cmake Warning: cmake 3.27.6 is already installed and up-to-date. To reinstall 3.27.6, run: brew reinstall cmake Warning: libusb 1.0.26 is already installed and up-to-date. To reinstall 1.0.26, run: brew reinstall libusb Warning: lsusb 1.0 is already installed and up-to-date. To reinstall 1.0, run: brew reinstall lsusb Requirement already satisfied: pip in /opt/homebrew/lib/python3.11/site-packages (23.2.1) Collecting hexformat==0.2 (from -r /Users/danielcagney/documents/coralmicro/scripts/requirements.txt (line 1)) Using cached hexformat-0.2-py3-none-any.whl Collecting hidapi==0.10.1 (from -r /Users/danielcagney/documents/coralmicro/scripts/requirements.txt (line 2)) Using cached hidapi-0.10.1.tar.gz (60 kB) Preparing metadata (setup.py) ... done Collecting progress==1.5 (from -r /Users/danielcagney/documents/coralmicro/scripts/requirements.txt (line 3)) Using cached progress-1.5-py3-none-any.whl Collecting pyserial==3.5 (from -r /Users/danielcagney/documents/coralmicro/scripts/requirements.txt (line 4)) Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB) Collecting pyusb==1.2.0 (from -r /Users/danielcagney/documents/coralmicro/scripts/requirements.txt (line 5)) Using cached pyusb-1.2.0-py3-none-any.whl (58 kB) Requirement already satisfied: setuptools>=19.0 in /opt/homebrew/lib/python3.11/site-packages (from hidapi==0.10.1->-r /Users/danielcagney/documents/coralmicro/scripts/requirements.txt (line 2)) (68.1.2) Building wheels for collected packages: hidapi Building wheel for hidapi (setup.py) ... error error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [19 lines of output] /opt/homebrew/lib/python3.11/site-packages/setuptools/__init__.py:84: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated. !! !! dist.fetch_build_eggs(dist.setup_requires) running bdist_wheel running build running build_ext Compiling hid.pyx because it changed. [1/1] Cythonizing hid.pyx /private/var/folders/th/c5bb5d0d4nvfytxblkshzdhw0000gn/T/pip-install-__i68mir/hidapi_95004ab0156645e5beeeaca9bdeb6eed/.eggs/Cython-3.0.2-py3.11.egg/Cython/Compiler/Main.py:384: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /private/var/folders/th/c5bb5d0d4nvfytxblkshzdhw0000gn/T/pip-install-__i68mir/hidapi_95004ab0156645e5beeeaca9bdeb6eed/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
已尝试多次执行
bash setup.sh,问题依旧存在。
解决方法
降级Cython版本:当前使用的Cython 3.0.2与旧版hidapi(0.10.1)存在兼容性问题,先卸载现有Cython,安装兼容版本:
pip uninstall -y cython pip install cython==0.29.36之后重新运行
bash setup.sh。直接安装预编译wheel包:跳过源码编译,直接安装对应环境的预编译hidapi包:
pip install hidapi==0.10.1 --only-binary :all:安装完成后再重新执行setup.sh即可。
更新hidapi版本:修改
/Users/danielcagney/documents/coralmicro/scripts/requirements.txt中的hidapi版本为最新兼容版(如0.14.0),再重新运行setup.sh,新版本已修复此类编译问题。
内容的提问来源于stack exchange,提问作者Daniel Cagney
相关产品推荐
相关产品推荐

