Sphinx cannot find module but Python can

浪子不回头ぞ 提交于 2020-07-08 12:04:41

问题


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:

  1. Add the path to the directory above statstuff to sys.path in conf.py:

    sys.path.insert(0, os.path.abspath('..'))
    
  2. Edit the automodule directives. Change

    .. automodule:: probability 
    

    to

    .. automodule:: statstuff.probability
    

    and so on.



来源:https://stackoverflow.com/questions/41925973/sphinx-cannot-find-module-but-python-can

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!