Search code examples
pythonpython-sphinxautodoc

Sphinx autodoc dies on ImportError of third party package


There's any way to exclude the import part of a module and then document it with sphinx-python? I have a module that imports another package (other different project) and then the sphinx gives this error:

""" File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.1.3-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object import(self.modname) File "/home/x/GitHub/project/mod_example1.py", line 33, in from other_pck import Klass, KlassStuff ImportError: No module named other_pck """

And if I comment the import parts in the module that calls/imports that package the sphinx can do the autodoc. I tried with all the sphinx autodoc modules: autoclass, automodule, etc... but the result is always the same once it try's to import the other package.

Thanks


Solution

  • You are fixing the issue wrong way. The correct way to fix the issue is to make Sphinx aware of your existing other packages as autodoc functionality must import Python packages to scan the source code. Python packages cannot be imported without all their dependencies resolved and you cannot cherry-pick lines of source code out of it, because this is how Python is built(*)

    Possible solutions are

    *) In theory you can, but this is outside the scope of Sphinx and this question