ImportError: No module named 'mypackage' during ReadTheDocs autodoc build
20K reputation · 01 Feb 2026, 22:05 UTC
ImportError in RTD Build Environment
The ReadTheDocs build logs report ImportError: No module named 'mypackage' when the Sphinx autodoc extension attempts to import the target module. Local builds succeed because the package is installed globally or the source directory is present on the local sys.path.
Environment Constraints
ReadTheDocs utilizes a clean virtual environment that installs only the dependencies specified in requirements.txt. Because the package source is not part of the documentation repository or listed as a dependency, the module is unavailable during the build process.
Configuration Uncertainty
There is an unresolved decision regarding the most stable method to expose the package path to the build environment. Options include modifying sys.path within conf.py, packaging the module as a pip-installable dependency for requirements.txt, or configuring the PYTHONPATH environment variable.
Specific Questions
- What is the recommended method for making a local package available to autodoc in a ReadTheDocs build?
- Does adding a relative path to
sys.pathinconf.pyensure reproducibility across different Python versions used by RTD? - Is there a documented way to include a local package via
.readthedocs.ymlwithout modifyingconf.py?