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

Python 3.12.x中Setuptools无法读取pyproject.toml指定的requirements.txt

问题详情

包结构

program_root/
    - src/
    - tests/ 
    - data/
        - templates/
    - docs/         
    - pyproject.toml        
    - README
    - requirements.txt

pyproject.toml配置

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

[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"*" = ["*.*"]

[project]
name = "file_ops"
version = "1.0.0"
authors = [
  {name="abc", email="abc@xyz.com" },
]
dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

构建报错情况

  • 使用setuptools==62.6.0时,报错:

    AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
    

    该版本虽首次支持dependencies = {file = ["requirements.txt"]}语法引用requirements.txt,但与Python 3.12不兼容——Python 3.12已弃用ImpImporter。

  • 使用其他setuptools版本时,会触发以下两类错误之一:

    • UTF-8解码失败:
      UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 
      
    • 后端子进程异常退出:
      Backend subproccess exited when trying to invoke get_requires_for_build_sdist
      

疑问与需求

  • 不确定适配当前环境的setuptools版本
  • 想了解setuptools历史中标记为Beta阶段的字段清单
  • 希望仅通过toml文件完成打包流程

后续进展与新需求

后续排查发现编码问题源于Windows系统默认编码,将requirements.txt转为UTF-8编码后构建成功,但需要实现以下任一操作:

  • 配置pip freeze > requirements.txt命令以UTF-8编码写入文件
  • 修改Windows系统默认编码为UTF-8

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 18:45:03