问题
Sphinx, the Python documentation generator, does not seem to understand my modules/packages. On make clean && make html, when this code is ran: from statstuff import statistics as stats, it outputs:
ImportError: No module named 'statstuff'
I have also tried to reference the module as from . import statistics as stats, since the modules are in the same package, but Sphinx outputs:
SystemError: Parent module '' not loaded, cannot perform relative import
Also, the config.py seems to be correctly configured as sys.path.insert(0, os.path.abspath('../statstuff/')), given that the documentation folder shares its parent folder with the statstuff folder.
Anyhow, here is the repository with the files: https://github.com/lucasmauro/statstuff
The problem occurs on statstuff/regression.py, lines 2 and 3: https://github.com/lucasmauro/statstuff/blob/master/statstuff/regression.py
The code runs normally with the Python interpreters, but Sphinx fails to find the module as the code (or configuration) was written.
Does anyone have a clue on how to solve this?
Thank you very much indeed!
回答1:
Since your modules are in a package called statstuff, I suggest the following:
Add the path to the directory above
statstufftosys.pathin conf.py:sys.path.insert(0, os.path.abspath('..'))Edit the
automoduledirectives. Change.. automodule:: probabilityto
.. automodule:: statstuff.probabilityand so on.
来源:https://stackoverflow.com/questions/41925973/sphinx-cannot-find-module-but-python-can