Sphinx autodoc dies from third party package ImportError
Is there a way to exclude the import part of the module and then document it using sphinx-python? I have a module that is importing another package (another project) and then 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, c from other_pck import Klass, KlassStuff ImportError: no module named other_pck ""
And if I comment out the import parts in the module that calls / imports the package the sphinx can do autodoc. I've tried with all authoc sphinx modules: autoclass, automodule, etc., but the result is always the same when it tries to import a different package.
thank
source to share
You are fixing the problem incorrectly. The correct way to fix the problem is to make Sphinx aware of your existing other packages, as autodoc functions have to import Python packages to scan source code. Python packages cannot be imported without resolving all dependencies, and you cannot strip lines of source code from it, because this is how Python is built (*)
Possible solutions:
-
Create a Python virtual environment that contains both Sphinx and other packages so they can see each other http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of- python-software-with-virtualenv /
-
Setting the PYTHONPATH environment variable or editing the sys.path in the Sphinx config file so that missing packages are added to the import list when Sphinx starts http://scienceoss.com/minimal-sphinx-setup-for-autodocumenting-python-modules/
*) In theory you can, but this is beyond the scope of the Sphinx and this question
source to share