无法通过pip安装sh模块与buildozer模块的问题排查及解决请求
解决Windows下pip安装buildozer失败的问题
问题概述
在Windows系统中执行pip install buildozer命令时安装失败,核心原因是buildozer依赖的sh模块在导入fcntl模块时出错——Windows系统原生不支持fcntl模块,最终导致元数据生成失败。
错误日志
C:\Users\Administrator>pip install buildozer Collecting buildozer Using cached buildozer-1.4.0-py3-none-any.whl (84 kB) Collecting pexpect Using cached pexpect-4.8.0-py2.py3-none-any.whl (59 kB) Collecting sh Using cached sh-1.14.3.tar.gz (62 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [8 lines of output] Traceback (most recent call last): File "", line 2, in File "", line 34, in File "C:\Users\Administrator\AppData\Local\Temp\pip-install-hg1fn8lo\sh_45a7ec2824b04794ac4fe58ef669a78f\setup.py", line 5, in import sh File "C:\Users\Administrator\AppData\Local\Temp\pip-install-hg1fn8lo\sh_45a7ec2824b04794ac4fe58ef669a78f\sh.py", line 37, in import fcntl ModuleNotFoundError: No module named 'fcntl' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. See above for details.
当前已安装包列表
| 包名 | 版本 |
|---|---|
| certifi | 2022.9.24 |
| charset-normalizer | 2.1.1 |
| docutils | 0.19 |
| ez-setup | 0.9 |
| idna | 3.4 |
| Kivy | 2.1.0 |
| kivy-deps.angle | 0.3.2 |
| kivy-deps.glew | 0.3.1 |
| kivy-deps.sdl2 | 0.4.5 |
| Kivy-Garden | 0.1.5 |
| pip | 22.3 |
| Pygments | 2.13.0 |
| pypiwin32 | 223 |
| pywin32 | 304 |
| requests | 2.28.1 |
| setuptools | 65.5.0 |
| supertools | 1.0.1 |
| urllib3 | 1.26.12 |
解决方案
方案一:使用WSL(推荐)
buildozer的开发和运行环境以Linux为主,很多依赖仅支持类Unix系统,WSL可以在Windows上模拟Linux环境,从根源解决兼容性问题:
- 启用Windows的WSL功能,并安装Ubuntu等Linux发行版
- 在WSL终端内执行以下命令:
sudo apt update && sudo apt upgrade -y sudo apt install python3 python3-pip -y pip3 install buildozer
方案二:尝试Windows兼容的sh模块(临时方案)
此方法仅能解决安装阶段的问题,后续buildozer运行可能仍出现其他兼容性错误:
- 先安装Windows兼容的
sh替代包:pip install sh-win - 再执行buildozer安装命令:
pip install buildozer
内容的提问来源于stack exchange,提问作者J Raghavendra
相关产品推荐
相关产品推荐

