You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Python Poetry强制使用指定版本setuptools解决pyhash构建错误?

解决Poetry环境下安装pyhash的setuptools版本冲突问题

问题原因

pyhash的构建依赖use_2to3特性,而setuptools > 58.0.0已经移除了对该特性的支持。直接在Poetry项目依赖中添加setuptools=58.0.0无效,是因为Poetry在构建阶段优先使用build-system配置里指定的setuptools版本,而非项目依赖中的版本。

解决方案

方法1:修改构建系统配置(推荐)

在项目根目录的pyproject.toml中,修改或添加[build-system]部分,强制指定构建时使用的setuptools版本:

[build-system]
requires = ["setuptools==58.0.0", "wheel"]
build-backend = "setuptools.build_meta"

修改后执行poetry install,Poetry会在构建pyhash时使用指定的低版本setuptools。

方法2:直接在Poetry虚拟环境中降级setuptools

  1. 进入Poetry虚拟环境:
    poetry shell
    
  2. 在虚拟环境内安装指定版本的setuptools:
    pip install setuptools==58.0.0
    
  3. 安装pyhash:
    poetry add pyhash
    

方法3:使用Poetry的依赖覆盖功能

在pyproject.toml中添加依赖覆盖规则,强制让Poetry使用指定版本的setuptools:

[tool.poetry.dependencies]
# 保留你原有的其他依赖
setuptools = "58.0.0"

[tool.poetry.overrides]
setuptools = "58.0.0"

执行以下命令更新依赖锁并重新安装:

poetry lock --no-update
poetry install

内容的提问来源于stack exchange,提问作者binford

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 18:45:46