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

本地GitLab部署ReadTheDocs执行migrate命令遇TypeError报错求助

部署ReadTheDocs时遇到dataclass(slots=True) TypeError问题分析

问题背景

  • 使用环境:Python3.9、Pip3.9,已通过python3.9 -m venv tutorial-env创建并激活虚拟环境
  • 操作步骤:执行pip install -r requirements.txt无报错,运行python3.9 /home/redhat/readthedocs.org/manage.py migrate时触发错误
  • 错误信息:
[debug    ] Using slumber v2.              [readthedocs.api.v2.client] api_host=http://127.0.0.1:8000 username=test

Traceback (most recent call last):

  File "/home/redhat/readthedocs.org/manage.py", line 11, in <module>

    execute_from_command_line(sys.argv)

  File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line

    utility.execute()

  File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute

    django.setup()

  File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "/home/redhat/tutorial-env/lib64/python3.9/site-packages/django/apps/registry.py", line 122, in populate

    app_config.ready()

  File "/home/redhat/readthedocs.org/readthedocs/core/apps.py", line 15, in ready

    import readthedocs.core.signals  # noqa

  File "/home/redhat/readthedocs.org/readthedocs/core/signals.py", line 17, in <module>

    from readthedocs.core.unresolver import unresolve

  File "/home/redhat/readthedocs.org/readthedocs/core/unresolver.py", line 16, in <module>

    @dataclass(slots=True)

TypeError: dataclass() got an unexpected keyword argument 'slots'

原因分析

Python 3.9的标准库dataclasses.dataclass未引入slots=True参数,该参数是Python 3.10新增的特性。当前安装的ReadTheDocs版本代码中使用了这个仅Python3.10+支持的参数,导致在Python3.9环境下运行报错。

解决方案

  • 方案一:升级Python版本
    将Python版本升级到3.10或更高版本,确保与ReadTheDocs代码的语法特性兼容,之后重新运行迁移命令即可。
  • 方案二:安装兼容Python3.9的ReadTheDocs版本
    如果无法升级Python,需要切换到ReadTheDocs支持Python3.9的版本分支,重新安装依赖后再执行迁移操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 20:10:25