为什么python 3.13安装pyradiomics总是失败,试了各种方法都不行

为什么python 3.13安装pyradiomics总是失败,试了各种方法都不行。镜像网站试了,aconda也试了,就是不知道哪错了问题。

这是报错信息:
Collecting pyradiomics
Using cached pyradiomics-3.1.0.tar.gz (34.5 MB)
Installing build dependencies: started
Installing build dependencies: finished with status ‘done’
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status ‘done’
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status ‘done’
Discarding https://files.pythonhosted.org/packages/03/c1/20fc2c50ab1e3304da36d866042a1905a2b05a1431ece35448ab6b4578f2/pyradiomics-3.1.0.tar.gz (from https://pypi.org/simple/pyradiomics/): Requested pyradiomics from https://files.pythonhosted.org/packages/03/c1/20fc2c50ab1e3304da36d866042a1905a2b05a1431ece35448ab6b4578f2/pyradiomics-3.1.0.tar.gz has inconsistent version: expected ‘3.1.0’, but metadata has ‘3.0.1a1’
Using cached pyradiomics-3.0.1.tar.gz (34.5 MB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status ‘error’

error: subprocess-exited-with-error

python setup.py egg_info did not run successfully.
exit code: 1

[38 lines of output]
D:\WibdowsTEMP\TEMP\pip-install-1er79fv_\pyradiomics_49c7d097d5ea49e7ab87a047294d08d2\setup.py:9: SetuptoolsDeprecationWarning: The test command is disabled and references to it are deprecated.
!!

      ********************************************************************************
      Please remove any references to `setuptools.command.test` in all supported versions of the affected package.

      This deprecation is overdue, please update your project and remove deprecated
      calls to avoid build errors in the future.
      ********************************************************************************

!!
from setuptools.command.test import test as TestCommand
D:\WibdowsTEMP\TEMP\pip-install-1er79fv_\pyradiomics_49c7d097d5ea49e7ab87a047294d08d2\versioneer.py:418: SyntaxWarning: invalid escape sequence ‘\s’
LONG_VERSION_PY[‘git’] = ‘’’
Traceback (most recent call last):
File “”, line 2, in
exec(compile(‘’’
~~~~^^^^^^^^^^^^
# This is – a caller that pip uses to run setup.py
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
…<31 lines>…
exec(compile(setup_py_code, filename, “exec”))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
‘’’ % (‘D:\WibdowsTEMP\TEMP\pip-install-1er79fv_\pyradiomics_49c7d097d5ea49e7ab87a047294d08d2\setup.py’,), “”, “exec”))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 34, in
File “D:\WibdowsTEMP\TEMP\pip-install-1er79fv_\pyradiomics_49c7d097d5ea49e7ab87a047294d08d2\setup.py”, line 79, in
version=versioneer.get_version(),
~~~~~~~~~~~~~~~~~~~~~~^^
File “D:\WibdowsTEMP\TEMP\pip-install-1er79fv_\pyradiomics_49c7d097d5ea49e7ab87a047294d08d2\versioneer.py”, line 1476, in get_version
return get_versions()[“version”]
~~~~~~~~~~~~^^
File “D:\WibdowsTEMP\TEMP\pip-install-1er79fv_\pyradiomics_49c7d097d5ea49e7ab87a047294d08d2\versioneer.py”, line 1408, in get_versions
cfg = get_config_from_root(root)
File “D:\WibdowsTEMP\TEMP\pip-install-1er79fv_\pyradiomics_49c7d097d5ea49e7ab87a047294d08d2\versioneer.py”, line 342, in get_config_from_root
parser = configparser.SafeConfigParser()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘configparser’ has no attribute ‘SafeConfigParser’. Did you mean: ‘RawConfigParser’?
[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.
hint: See above for details.

问题分析

pip install pyradiomics 在 Python 3.13 上会撞上两个还没修好的坑:① Python 3.12 起彻底移除了 configparser.SafeConfigParser,而 PyRadiomics 仍携带老旧的 Versioneer 脚本调用它;② PyPI 里的 3.1.0 源码包带错了内部版本号(3.0.1a1),pip 把它当成“损坏”包直接丢弃。两个问题叠在一起,安装自然失败。当前官方发行版仅保证到 Python 3.11(甚至文档里还停在 3.9),因此最简单、最稳妥的办法就是在 conda/venv 里切回 3.11 或更早,并从 conda‑forge 或预编译 wheel 安装。下面把原理和可选解决方案按步骤列出来。


1 为什么 Python 3.13 会装不上

1.1 SafeConfigParser 已被删除

  • Python 3.12 把 configparser.SafeConfigParserreadfp() 一并移除;任何还在调用它们的旧代码都会抛 AttributeError (GitHub, GitHub)。
  • PyRadiomics 使用的 Versioneer 0.21 写于 2020 年前后,内部硬编码了 SafeConfigParser,因此在 3.12+ 触发上述错误 (GitHub)。

1.2 源码包元数据不一致

PyPI 上标识为 pyradiomics‑3.1.0.tar.gz 的包里头却声明版本 3.0.1a1,pip 检查到不一致就会 “Discarding … inconsistent version”,正好与你的日志对上 (GitHub)。这说明官方发布流程本身也需要修补。


2 官方目前支持到哪一版 Python?

  • 官方文档和 Release Notes 只列出 3.7–3.9 (最近一次打包时 CI 还停在这些版本)(pyradiomics.readthedocs.io, pyradiomics.readthedocs.io)。
  • PyPI 页面里预编译的 wheel 也只到 cp311 (Python 3.11)为止 (Wheelodex)。
  • GitHub 上已有用户在 3.12 报同样的问题,但维护者尚未合并修复 PR (GitHub)。

结论:3.12/3.13 暂时属于“未测试 / 不支持”。


3 最省事的解决方案——切回稳定版 Python

场景 推荐动作 关键命令
conda 用户 建立干净环境并安装预编译包 conda create -n radio311 python=3.11 pyradiomics -c conda-forge
pip/venv 用户 用 pyenv 或官方安装包下个 3.11,再装 wheel bash\npython3.11 -m venv venv\nsource venv/bin/activate\npip install --upgrade pip\npip install pyradiomics==3.1.0\n
需要脚本化部署 在 Docker 里锁定 3.11 基础镜像 FROM python:3.11-slim

这样可以直接用到官方 wheel,省去本地编译 C 扩展的麻烦,也不用碰 Versioneer (PyPI)。


4 仍想在 Python 3.13 上使用的两条路

:warning: 都属“手动打补丁”,生产环境不建议。

4.1 自己打补丁 + 本地安装

git clone https://github.com/Radiomics/pyradiomics.git
cd pyradiomics
# 更新 Versioneer,替换对 SafeConfigParser 的调用
python -m pip install --upgrade pip setuptools_scm
# Quick‑fix:把 versioneer.py 中 SafeConfigParser → ConfigParser,readfp → read_file
sed -i "s/SafeConfigParser/ConfigParser/g" versioneer.py
sed -i "s/readfp/read_file/g" versioneer.py
python -m pip install .

原理同社区用户给其他包打补丁的做法 (GitHub, GitHub)。

4.2 等待(或协助)官方合并 PR

GitHub 已有针对 Python 3.12/3.13 的修复 PR,由于项目活跃度一般,短期内可能还需手动从 fork 安装:

pip install git+https://github.com/<your-fork>/pyradiomics@py312-fix

5 额外提示

  1. 不要混用全局 pip 与 Anaconda:同一机器可以并存,但环境要隔离,否则 python.exe 指向哪个版本很容易搞混。

  2. 仍想用 3D Slicer

  3. 自动化构建:如果你在 CI/CD 里用 pip install pyradiomics,务必先 actions/setup-python 选择 ≤ 3.11,避免后续脚本失效。

  4. 关注官方 issue #893 / #886:一旦维护者释放新的 wheel,你就可以直接回到 pip install pyradiomics (GitHub, GitHub)。


6 小结

PyRadiomics 目前并未适配 Python 3.12+;核心阻碍是旧 Versioneer 对 SafeConfigParser 的调用,以及 3.1.0 源码包的元数据错误。
首选方案:在隔离环境中退回 Python 3.11(或 Slicer/Radiomics Docker),直接用官方 wheel。
实验方案:手动 patch Versioneer 或从带修复的 fork 编译安装。
等待官方正式支持前,这两步可以让你继续使用 PyRadiomics 而不被语言升级卡住。