Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 > ...}
like image 754
Alex Cavanaugh Avatar asked Feb 21 '19 20:02

Alex Cavanaugh


People also ask

Why I Cannot import module in Python?

This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.


1 Answers

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.

like image 125
Ingako Avatar answered Oct 21 '22 09:10

Ingako