0

I am adding rst files to an existing repository using Sphinx v6.1.3 with sphinx.ext.autodoc extension.

when running make html the new rst file causes an error:

Extension error (sphinx_automodapi.automodsumm):
Handler <function process_automodsumm_generation at 0x7fedb8d30430> for event 'builder-inited' threw an exception (exception: No module named 'pandas')
make: *** [html] Error 2

(pandas is one import issue I'm having, but also having the issue with another import that I can't install in the environment, so using pandas for the sake of this question)

Sphinx documentation offers the solution to use

autodoc_mock_imports = ["pandas"]

which I added to config.py

I then re-ran

$ make html

but the error persisted.

My folder structure is:

project_folder
└──doc
   ├── build
   ├── make.bat
   ├── Makefile
   └── source
      ├── conf.py
      ├── index.rst
      ├── _static
      └── problem
          └── index.rst
└──src
   └──project
      └──problem
         ├──__init__.py
         └──problem.py

my skimmed down root file (project_folder/doc/source/index.rst) is:

Project Documentation
===============================================

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

   problem/index
   
Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

my skimmed down conf.py (I went heavy on sys.path seeing if that would help)

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys

sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, os.path.abspath("../../src"))
sys.path.insert(0, os.path.abspath("../../src/project"))
sys.path.insert(0, os.path.abspath("../../src/project/problem"))

autodoc_mock_imports = ['pandas']


extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.imgmath',
    'sphinx.ext.napoleon',
    'sphinx.ext.intersphinx',
    'sphinx.ext.autosummary',
    'sphinx_automodapi.automodapi'
]

templates_path = ['_templates']

exclude_patterns = ['project']

html_theme = 'sphinx_rtd_theme'
pygments_style = 'sphinx'


default_role = 'py:obj'

Finally, specific rst file (project_folder/doc/source/problem/index.rst) is:

Problem
=======

This package contains modules for Problem

Reference/API
-------------
.. module:: Project.problem

.. automodapi:: project.problem.problem
   :no-inheritance-diagram:

I appreciate any input!

mzjn
  • 48,958
  • 13
  • 128
  • 248
Sapps
  • 1
  • 1
  • Seems related to https://github.com/astropy/sphinx-automodapi/issues/148 – mzjn Jan 12 '23 at 21:00
  • Are there any more hints about the error? From my experience, syntax error in python script may also result in similar error. The syntax error I made was that use module os while forgotten to import it first. Is it possible that you forget to import pandas before use it? – Ian Jul 26 '23 at 07:50

1 Answers1

0

Try running make clean first before running make html again to clear the existing build directory.

Watchanan
  • 419
  • 6
  • 13