skip to Main Content

I have written the documentation for a Node.js library using Sphinx. On my local PC, I can generate the html docs without any problems. However, when I try to publish it on Read the Docs, the compilation fails. Here is my .readthedocs.yaml file.

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
  os: ubuntu-22.04
  tools:
    python: "3.11"
    # You can also specify other tool versions:
    # nodejs: "19"
    # rust: "1.64"
    # golang: "1.19"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
   configuration: docs/conf.py

and here my conf.py

project = 'My-Library'
copyright = '2023, Hector E. Socarras'
author = 'Hector E. Socarras'
release = '1.0.0'

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

extensions = ['sphinx.ext.autosectionlabel', "sphinx_rtd_theme"]

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

# on_rtd is whether we are on readthedocs.org
#on_rtd = os.environ.get('READTHEDOCS', None) == 'True'

#if not on_rtd:  # only import and set the theme if we're building docs locally    
#import sphinx_rtd_theme
        


#import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_static_path = ['static']

It compile succesfully once, then always fails with following messages

Extension error:
Could not import extension sphinx_rtd_theme (exception: No module named 'sphinx_rtd_theme')

if add a requeriments.txt with sphinx_rtd_theme then fails with following messages

ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.

Obviously, it’s not a Python package.

I need help, I would like to have the documentation available on Read the Docs.

2

Answers


  1. Chosen as BEST ANSWER

    I read this on readthedocs FAQ:

    sphinx-rtd-theme:
    
        Projects created before October 20, 2020 (January 21, 2021 for About Read the Docs for Business) use 0.4.3. New projects use the latest version. Projects created after August 7, 2023 won’t install this dependency by default.
    

    So, the issue regarding "Could not import extension sphinx_rtd_theme" is for projects created after August 7, 2023.


  2. You need to install the Sphinx theme dependency on Read the Docs. To do so, you have to create a requirements.txt file with the following content:

    sphinx-rtd-theme==1.2.2
    

    Then, modify your .readthedocs.yaml file to tell Read the Docs to install these requirements:

    python:
      install:
        - requirements: "requirements.txt"
    

    There is more information about this change on Read the Docs on its blog: https://blog.readthedocs.com/python-core-requirements-changed/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search