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

ReadTheDocs Sphinx构建报错:index.rst文件未找到

解决ReadTheDocs构建Sphinx文档时index.rst未找到的问题

错误详情

构建过程中抛出核心错误:

Running Sphinx v7.3.7
making output directory... done
WARNING: html_static_path entry '_static' does not exist
building [mo]: targets for 0 po files that are out of date
writing output... 
building [html]: targets for 0 source files that are out of date
updating environment: [new config] 0 added, 0 changed, 0 removed
reading sources... 

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/betterpathlib/envs/latest/lib/python3.12/site-packages/sphinx/cmd/build.py", line 337, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/docs/checkouts/readthedocs.org/user_builds/betterpathlib/envs/latest/lib/python3.12/site-packages/sphinx/application.py", line 351, in build
    self.builder.build_update()
  File "/home/docs/checkouts/readthedocs.org/user_builds/betterpathlib/envs/latest/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 293, in build_update
    self.build(to_build,
  File "/home/docs/checkouts/readthedocs.org/user_builds/betterpathlib/envs/latest/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 313, in build
    updated_docnames = set(self.read())
                           ^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/betterpathlib/envs/latest/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 422, in read
    raise SphinxError('root file %s not found' %
sphinx.errors.SphinxError: root file /home/docs/checkouts/readthedocs.org/user_builds/betterpathlib/checkouts/latest/docs/index.rst not found

Sphinx error:
root file /home/docs/checkouts/readthedocs.org/user_builds/betterpathlib/checkouts/latest/docs/index.rst not found

当前相关配置:

  • .readthedocs.yaml片段:
...

# Build documentation in the "docs/" directory with Sphinx
sphinx:
  configuration: docs/conf.py
  • docs/conf.py完整内容:
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'betterpathlib'
copyright = '2024, xx'
author = 'xx'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']

解决方案

1. 创建缺失的index.rst文件

Sphinx强制要求根目录下存在index.rst作为文档入口,在项目的docs/目录下创建该文件,基础示例内容如下:

Welcome to betterpathlib's documentation!
========================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

# 后续可按需添加子文档路径,比如:
# installation
# usage

2. 处理_static目录警告

错误日志中附带的html_static_path entry '_static' does not exist警告,可二选一处理:

  • 在docs/目录下创建_static文件夹,用于存放CSS、JS等静态资源
  • 修改docs/conf.py中的配置项:
    html_static_path = []
    

3. 验证项目文件结构

确保最终项目结构符合以下规范:

betterpathlib/
├── .readthedocs.yaml
├── docs/
│   ├── conf.py
│   ├── index.rst
│   ├── _templates/  # 可选,使用自定义模板时保留
│   └── _static/     # 可选,根据警告处理方式决定是否创建

完成以上操作后,提交代码到GitHub仓库,重新触发ReadTheDocs构建即可。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 23:17:43