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

如何使基于pyproject.toml的Python模块兼容Python3.6及以上构建?

解决Python3.6环境下构建UNKNOWN包的问题

原因分析

旧版本的build模块(0.9.0)对PEP 621规范的pyproject.toml支持不完善,且你的配置缺少PEP 517要求的[build-system]段,导致工具无法正确识别项目配置和代码。

解决方案

1. 补充pyproject.toml的构建系统配置

在现有pyproject.toml开头添加以下内容,明确指定构建后端:

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

这是PEP 517的强制要求,旧版build模块依赖这段配置来识别构建工具链。

2. 升级build模块到兼容Python3.6的版本

在RHEL7的Python3.6环境中执行:

pip install --upgrade "build>=0.10.0"

build 0.10.0是支持Python3.6的最后几个版本之一,对PEP 621的pyproject.toml支持更完善。升级后再执行构建命令:

python3.6 -m build --wheel .

3. 备选方案:补充传统setup.py和setup.cfg配置

如果升级build模块仍有问题,可添加传统配置文件适配旧工具链:

  • 创建setup.py:
from setuptools import setup
setup()
  • 创建setup.cfg,内容与你的pyproject.toml配置对应:
[metadata]
name = Mysms
version = 0.1
author = Me Me
author_email = Me@example.com
description = Fetch specified secrets-file(s) from My's SMS-portal
long_description = file: README.md
long_description_content_type = text/markdown
keywords = SMS, secrets
classifiers =
    Development Status :: 4 - Beta
    Topic :: Software Development :: Secrets
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3.6
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9
    Programming Language :: Python :: 3.10
    Programming Language :: Python :: 3.11

[options]
python_requires = >=3.6
py_modules = Mysms
install_requires =
    requests
    requests_kerberos
    pyspnego

[options.extras_require]
decodejwt =
    pyjwt

[options.entry_points]
console_scripts =
    Mysms = Mysms:main

之后可直接用setuptools构建:

python3.6 setup.py bdist_wheel

或继续使用build模块构建。

内容的提问来源于stack exchange,提问作者Mikhail T.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 19:20:02