安装spidev时wheel构建失败报错,已尝试多种方法仍未解决
解决Windows下安装spidev构建wheel失败的问题
核心问题
spidev是专为Linux系统开发的SPI总线访问库,Windows系统原生不支持SPI设备操作——这才是导致构建失败的根本原因。即便你安装了符合要求的VC++编译工具,也无法在Windows上正常构建和使用spidev。
可行解决方案
方案1:使用WSL2(推荐)
WSL2提供完整的Linux环境,支持SPI硬件访问:
- 开启Windows的WSL功能,安装Ubuntu等Linux发行版
- 在WSL中安装Python和pip:
sudo apt update && sudo apt install python3 python3-pip - 直接安装依赖:
pip3 install mcp3008==1.0.0 - 确保Windows设备已启用SPI硬件,并且WSL能识别到对应的SPI设备(可能需要额外配置硬件权限)
方案2:改用Windows兼容的MCP3008驱动库
放弃依赖spidev,使用支持Windows的第三方库,比如Adafruit的CircuitPython驱动:
- 安装库:
pip install adafruit-circuitpython-mcp3xxx - 该库支持通过GPIO模拟SPI或硬件SPI(如果你的Windows设备支持),无需依赖spidev
关于VC++编译工具的补充说明
如果一定要尝试编译(不推荐,因为平台不兼容),需确保安装VC++ Build Tools时勾选了**Desktop development with C++**组件,包含MSVC编译器、Windows SDK等核心模块,而不是仅安装Visual Studio IDE。但即便完成这些,spidev依然无法在Windows上正常工作。
原报错日志
"C:\Program Files (x86)\Thonny\python.exe" -m pip --disable-pip-version-check --no-color install --no-warn-script-location --user --user --upgrade mcp3008==1.0.0 Collecting mcp3008==1.0.0 Using cached mcp3008-1.0.0-py3-none-any.whl (15 kB) Collecting spidev Using cached spidev-3.6.tar.gz (11 kB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Installing backend dependencies: started Installing backend dependencies: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'done' Building wheels for collected packages: spidev Building wheel for spidev (pyproject.toml): started Building wheel for spidev (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error × Building wheel for spidev (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [20 lines of output] C:\Users\sasha\AppData\Local\Temp\pip-build-env-hsttcn2i\overlay\Lib\site-packages\setuptools\dist.py:745: SetuptoolsDeprecationWarning: Invalid dash-separated options !! ******************************************************************************** Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead. By 2023-Sep-26, you need to update your project and remove deprecated calls or your builds will no longer be supported. See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details. ******************************************************************************** !! opt = self.warn_dash_deprecation(opt, section) running bdist_wheel running build running build_ext building 'spidev' extension error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for spidev Failed to build spidev ERROR: Could not build wheels for spidev, which is required to install pyproject.toml-based projects Error: process returned with code 1
内容的提问来源于stack exchange,提问作者HockeyCRAZEY
相关产品推荐
相关产品推荐

