GitHub Actions+Poetry构建失败:调用build_wheel时后端子进程退出
Poetry + GitHub Actions 构建失败问题求助
问题背景
使用Poetry进行依赖管理的GitHub Actions工作流此前运行正常,近期突然在虚拟环境创建和包安装步骤失败,未修改过工作流文件。相关环境信息:
- GitHub Actions runner 使用 Python 3.10.14
- 已尝试安装最新版
wheel和setuptools,问题未解决
完整错误日志
[virtualenv] create virtual environment via CPython3Posix(dest=/tmp/tmp0id2fedr/.venv, clear=False, no_vcs_ignore=False, global=False) 2024-06-19T20:48:12.0128143Z [virtualenv] create folder /tmp/tmp0id2fedr/.venv/bin 2024-06-19T20:48:12.0128439Z [virtualenv] create folder /tmp/tmp0id2fedr/.venv/lib/python3.10/site-packages ... 2024-06-19T20:48:12.0142856Z [virtualenv] add activators for Bash, CShell, Fish, Nushell, PowerShell, Python 2024-06-19T20:48:12.0143272Z Source (PyPI): 217 packages found for setuptools >=40.8.0 2024-06-19T20:48:12.0143401Z Source (PyPI): 1 packages found for setuptools >=40.8.0 2024-06-19T20:48:12.0143457Z [build:build] Getting build dependencies for wheel... ... 2024-06-19T20:48:12.0152045Z 1 ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/chef.py:121 in prepare 2024-06-19T20:48:12.0152216Z 119│ if archive.is_dir(): 2024-06-19T20:48:12.0152536Z 120│ destination = output_dir or Path(tempfile.mkdtemp(prefix="poetry-chef-")) 2024-06-19T20:48:12.0152846Z → 121│ return self._prepare(archive, destination=destination, editable=editable) 2024-06-19T20:48:12.0152962Z 122│ 2024-06-19T20:48:12.0153246Z 123│ return self._prepare_sdist(archive, destination=output_dir) 2024-06-19T20:48:12.0153254Z 2024-06-19T20:48:12.0153357Z ChefBuildError 2024-06-19T20:48:12.0153367Z 2024-06-19T20:48:12.0153548Z Backend subprocess exited when trying to invoke build_wheel 2024-06-19T20:48:12.0153790Z 2024-06-19T20:48:12.0154053Z We need both setuptools AND wheel packages installed for bdist_wheel to work. Try running: pip install wheel 2024-06-19T20:48:12.0154149Z 2024-06-19T20:48:12.0154157Z 2024-06-19T20:48:12.0154533Z at ~/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/chef.py:164 in _prepare 2024-06-19T20:48:12.0154650Z 160│ 2024-06-19T20:48:12.0154912Z 161│ error = ChefBuildError("\n\n".join(message_parts)) 2024-06-19T20:48:12.0155024Z 162│ 2024-06-19T20:48:12.0155204Z 163│ if error is not None: 2024-06-19T20:48:12.0155394Z → 164│ raise error from None 2024-06-19T20:48:12.0155507Z 165│ 2024-06-19T20:48:12.0155680Z 166│ return path 2024-06-19T20:48:12.0155796Z 167│ 2024-06-19T20:48:12.0156109Z 168│ def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path: 2024-06-19T20:48:12.0169670Z ##[error]Process completed with exit code 1.
核心错误信息
ChefBuildError Backend subprocess exited when trying to invoke build_wheel We need both setuptools AND wheel packages installed for bdist_wheel to work. Try running: pip install wheel
解决建议
- 确保Poetry虚拟环境内安装wheel和setuptools
不要直接在runner全局环境安装,而是在执行poetry install前,让Poetry在自身创建的虚拟环境中安装依赖:poetry run pip install --upgrade setuptools wheel - 固定Poetry版本
近期Poetry版本更新可能引入兼容性问题,在工作流中指定之前能正常运行的版本,例如:pip install poetry==1.8.3 - 清理GitHub Actions缓存
缓存的旧虚拟环境或依赖包可能导致异常,可在工作流中添加缓存清理步骤,或手动前往仓库的Actions页面清理缓存 - 明确构建系统依赖
在项目的pyproject.toml中指定构建所需的依赖版本:[build-system] requires = ["setuptools>=61.0", "wheel"] build-backend = "setuptools.build_meta" - 使用标准化的Poetry安装方式
改用官方的Python setup action配合Poetry安装action,确保环境一致性:- name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.10" - name: Install Poetry uses: snok/install-poetry@v1 with: version: 1.8.3 virtualenvs-create: true virtualenvs-in-project: true
内容的提问来源于stack exchange,提问作者Nadav
相关产品推荐
相关产品推荐

