[英]Sphinx autodoc can't find module
我是 sphinx 的新手,需要帮助来弄清楚为什么我会收到以下错误:
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
in conf.py
如Sphinx 中推荐的那样:autodoc can`t import module
sphinx-build 失败 - autodoc 无法导入/找到模块@ryandillan 建议将sys.path.insert(0, os.path.abspath('..'))
到config.py
修复了我的404“未找到索引” index.rst
model index
错误
我已按照另一个 stackoverflow 线程中的建议将extensions = ['sphinx.ext.autodoc']
到config.py
。
关于我做错了什么的任何建议?
根据您的目录结构,添加到sys.path
的目录应该是../src
有关更一般的答案,请考虑如果您想在 Python CLI 中成功import module
您需要位于哪个目录中。 该目录是您希望 Sphinx 在您的路径中拥有的目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.