10

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 > ...}
mzjn
  • 48,958
  • 13
  • 128
  • 248
Alex Cavanaugh
  • 415
  • 1
  • 5
  • 16

4 Answers4

3

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.

Ingako
  • 393
  • 4
  • 14
  • Fantastic! I guess Sphinx shouldn't gobble up the warnings from the python interpreter. – Colin Feb 21 '22 at 14:40
2

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.

  • 1
    I think the module loading path is correct because it is picking up on some of the modules in the folder. I'll add an edit now that shows my `conv_table`, but my `__init__.py` only contains comments. – Alex Cavanaugh Feb 21 '19 at 22:32
  • 3
    Also add any lines in your `conf.py` that defines `sys.path`. – Steve Piercy Feb 22 '19 at 08:12
  • 1
    I have two lines for that: ```sys.path.insert(0, os.path.abspath('.'))``` ```sys.path.append('Main')``` – Alex Cavanaugh Feb 22 '19 at 15:12
  • @AlexCavanaugh is the code open source? it's hard to see what's going on with the path without the rest of the source –  Feb 22 '19 at 17:49
  • It isn't open source unfortunately. But I would think I should be able to do something like `sys.path.append(os.path.abspath('./Main/Scripts'))` since Sphinx is run out of the `Project` directory. Does that sound right? – Alex Cavanaugh Feb 22 '19 at 20:41
0

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/')

-1

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.

  • Strange answer. There is nothing in the question that makes it likely that installing sphinxcontrib-bibtex would solve the problem. – mzjn Feb 17 '23 at 09:41
  • haha, i know that, my perspective of commenting this doesn't mean that i think it will resolve your problem but it may for many other people who will see this thread for some potential solution just like me. as for whether it seems likely to resolve the problem or not, i thought the same thing but it unexpectedly worked for me and i didn't bothered to debug the reason, you can try and see if it works for you. – Waqar Ahmad Feb 20 '23 at 15:22