Alex Cavanaugh
Alex Cavanaugh

Reputation: 435

Sphinx autodoc fails to import module

I'm trying to document a project using Sphinx, and am running into an issue where only some modules are being imported from a folder. My project structure looks like this:

Project
|
|--Main
|    |--Scripts
|          __init__.py
|          libsmop.py
|          conv_table.py
|          f_discrim.py
|          recipes.py
|          ...

When I try to run make html, libsmop and recipes are imported without any issue, however conv_table and f_discrim get the following error:

WARNING: autodoc: failed to import module u'conv_table' from module u'Scripts'; the following exception was raised:No module named conv_table

I don't think it's my config file because it's finding all of the files when I run sphinx-apidoc -o _rst Main/Scripts and I've confirmed that they appear in the resulting Scripts.rst file.

Why is autodoc finding some modules but not others?

Edit: conv_table.py is of this form:

import re
import numpy as np

"""
conv_table dictionary at the bottom of this file maps from matlab functions
to their python equivalents.
"""

def get_args(line,separator=",", open_char='(', close_char=')'):
    """Returns the arguments of line

    >>> get_args('ones(3,1,length(arr))')

...
< a bunch of function definitions>
...

conv_table = {... < a very big dictionary > ...}

Upvotes: 12

Views: 16280

Answers (4)

Waqar Ahmad
Waqar Ahmad

Reputation: 92

installing this library in your environment should resolve the problem as of now:

pip install sphinxcontrib-bibtex

after running the make html command it may warn you about the configuration problems.

Upvotes: -2

Maher Nouredline
Maher Nouredline

Reputation: 81

I had a similar issue like yours, the fix was to append the path that holds that module inside the ../source/conf.py file using

sys.path.insert(0, os.path.abspath('whatever relative path works for your folder structure')) sys.path.append('/path/to/the/conv_table/')

Upvotes: 0

Ingako
Ingako

Reputation: 393

Since your autodoc is picking up some of the modules, it may be because the dependencies of the failed modules are either 1) not imported correctly or 2) not installed under your python environment. You will want to check if all the import statements work within your failed modules.

Upvotes: 3

user9903
user9903

Reputation:

You will want to check the module loading path, according to the Sphinx docs:

For Sphinx (actually, the Python interpreter that executes Sphinx) to find your module, it must be importable. That means that the module or the package must be in one of the directories on sys.path – adapt your sys.path in the configuration file accordingly.

Also it would be useful to know how your __init__.py in Scripts directory looks like and how the conv_table module looks like as well.

Upvotes: 2

Related Questions