代码之家  ›  专栏  ›  技术社区  ›  Adam

Sphinx Autodoc找不到模块

  •  0
  • Adam  · 技术社区  · 5 年前

    我对狮身人面像还不熟悉,需要帮助来找出我为什么会出现以下错误:

    WARNING: autodoc: failed to import module 'employe_dao' from module 'models'; the following exception was raised:
    No module named 'models'
    

    我的项目结构是:

    |--master_project
       |--sub_project
          |--docs
            |--build
            |--conf.py
            |--index.rst
            |--Makefile
            |--models.rst
            |--src.models.rst
            |--src.rst
          |--src
            |--models
              |--employee.py
              ...
            |--__init__.py
            |--data_extractor.py
            |--optimiser.py
        enter code here
            ...
    

    这是个狙击手 index.rst

    ...
    
    .. toctree::
       :maxdepth: 2
       :caption: Contents:
    
    .. automodule::src
       :members:
       :undoc-members:
       :show-inheritance:
    
    .. automodule::models
       :members:
       :undoc-members:
       :show-inheritance:
    
    ...
    
    * :ref:`modindex`
    
    

    我补充说 sys.path.insert(0, os.path.abspath('./sub_project')) 和取消注释 import os, import sys 在里面 conf.py 如中所述 Sphinx: autodoc can`t import module

    sphinx-build fail - autodoc can't import/find module @Ryandillan建议添加 sys.path.insert(0, os.path.abspath('..')) config.py 修正了我的 404“找不到索引” 误差为 model index 对于 索引索引

    我补充说 extensions = ['sphinx.ext.autodoc'] 组态软件 在另一个stackoverflow线程中推荐。

    有什么我做错的建议吗?

    0 回复  |  直到 5 年前
        1
  •  1
  •   Ammar Askar    5 年前

    根据目录结构,要添加到的目录 sys.path 应该是 ../src

    要获得更一般的答案,请考虑如果您想 import module 在python cli中成功。这个目录就是您希望sphinx在您的路径中拥有的目录。