Sphinx cannot find my python files. Says 'no module named …'

后端 未结 3 1729
太阳男子
太阳男子 2020-12-06 23:09

I have a question regarding the Sphinx autodoc generation. I feel that what I am trying to do should be very simple, but for some reason, it won\'t work.

I have a P

3条回答
  •  时光取名叫无心
    2020-12-06 23:34

    sys.path.insert(0, os.path.abspath('../..'))
    

    That's not correct. Steve Piercy's comment is not entirely on point (you don't need to add a __init__.py since you're using a simple module) but they're right that autodoc will try to import the module and then inspect the content.

    Hoever assuming your tree is

    doc/conf.py
    src/stack.py
    

    then you're just adding the folder which contains your repository to the sys.path which is completely useless. What you need to do is add the src folder to sys.path, such that when sphinx tries to import stack it finds your module. So your line should be:

    sys.path.insert(0, os.path.abspath('../src')
    

    (the path should be relative to conf.py).

    Of note: since you have something which is completely synthetic and should contain no secrets, an accessible repository or a zip file of the entire thing makes it much easier to diagnose issues and provide relevant help: the less has to be inferred, the less can be wrong in the answer.

提交回复
热议问题