Sphinx is a powerful Python documentation generator that creates intelligent and beautiful documentation from reStructuredText or Markdown sources. It is currently at version 9.1.0, with major releases typically annually and patch releases occurring frequently. It leverages Docutils for parsing and processing text, and is highly extensible.
pip install sphinxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically build Sphinx documentation for a Python project. It creates a minimal project structure including `conf.py` (configuration), `index.rst` (main document), `my_module.py` (Python code), and `modules.rst` (autodoc entry), then invokes Sphinx to generate HTML output.
Upgrade your Python environment to 3.12 or higher, or pin your Sphinx dependency to `<9.1.0` if Python 3.11 support is critical.
Ensure that `docutils` is updated to version 0.21 or higher. Typically, `pip install sphinx` will handle this automatically, but manual intervention may be needed in environments with locked dependencies.
Custom Sphinx extensions that override or use `create_source_parser` must update their method signature to accept `config` and `env` parameters instead of `app`.
Verify that all source files (e.g., `.rst`, `.md`, `.py` for autodoc) are correctly encoded (typically UTF-8) and do not contain characters that are invalid for their declared encoding.
Refactor code interacting with autodoc options to use attribute access (e.g., `options.key`) rather than dictionary-style access (e.g., `options['key']`) to ensure forward compatibility.
Add the path to your Python project's root directory (or the directory containing the modules to be documented) to `sys.path` within your `conf.py` file, typically using `sys.path.insert(0, os.path.abspath('.'))` or `os.path.abspath('../..')` depending on your `conf.py` location.If you encounter unexpected behavior or errors with custom extensions and `autodoc`, you can temporarily revert to the legacy implementation by setting `autodoc_use_legacy_class_based = True` in your `conf.py`. Report issues to the Sphinx project.
Review the specified line in your Python source file (e.g., `/script.py`, line 26 in the provided output) and correct any syntax errors. Ensure that your Python code is valid and can be executed by the Python interpreter.
Review the Python code in your script at the indicated line number (e.g., line 24 in `/script.py`) and surrounding lines to correct the syntax error. Ensure all string literals, function calls, and statements are correctly formed according to Python syntax rules. Pay attention to commas, parentheses, and string delimiters.
Ensure Sphinx is installed (`pip install sphinx`) and your virtual environment is activated, or verify that the Python scripts directory containing `sphinx-build` is included in your system's PATH.
Rename duplicate labels in your source files to ensure each label used for internal linking is unique across the entire Sphinx project.
Install the missing theme or extension package using pip: `pip install sphinx_rtd_theme` (or the appropriate package name).
Examine the full traceback provided after the error message to locate the specific line and nature of the error in `conf.py` and correct the Python code or configuration value.
Add the parent directory of your module to `sys.path` in your `conf.py` file, typically using `import os, sys; sys.path.insert(0, os.path.abspath('.'))` or `os.path.abspath('../../')`.