Search code examples
python-sphinxautodoc

Sphinx error: Unknown directive type "automodule" or "autoclass"


I need to document my Python project using Sphinx. But I can't use autodoc.

When I config my project I select the option "extension autodoc", but now if I use

.. autoclass:: Class

I get an error:

ERROR: Unknown directive type "autoclass"

I configure the PYTHONPATH, and now it's good. But I already have this problem.

My index file is:

.. ATOM documentation master file, created by
   sphinx-quickstart on Thu Nov 22 15:24:42 2012.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to ATOM's documentation!
================================

Contents:

.. toctree::
   :maxdepth: 2

.. automodule:: atom

Indices and tables
==================

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

Solution

  • The same thing happened to me! To fix it, go to the line in conf.py that says something like this:

    extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode']
    

    Yours will probably look different. Anyway, add 'sphinx.ext.autodoc' to the list. e.g.

    extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc']
    

    If it was:

    extensions = []
    

    then you'd change it to:

    extensions = ['sphinx.ext.autodoc']
    

    Sources: Sphinx documentation: ERROR: Unknown directive type "program-output"