[英]Sphinx autodoc can't find module
I am new to sphinx and need help to figure out why I am getting the following error:我是 sphinx 的新手,需要帮助来弄清楚为什么我会收到以下错误:
WARNING: autodoc: failed to import module 'employe_dao' from module 'models'; the following exception was raised:
No module named 'models'
My project structure is:我的项目结构是:
|--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
...
This is a snipet from index.rst
这是来自
index.rst
...
.. toctree::
:maxdepth: 2
:caption: Contents:
.. automodule::src
:members:
:undoc-members:
:show-inheritance:
.. automodule::models
:members:
:undoc-members:
:show-inheritance:
...
* :ref:`modindex`
I have added sys.path.insert(0, os.path.abspath('./sub_project'))
and uncomment import os, import sys
in conf.py
as recommened in Sphinx: autodoc can`t import module我添加了
sys.path.insert(0, os.path.abspath('./sub_project'))
并取消注释import os, import sys
in conf.py
如Sphinx 中推荐的那样:autodoc can`t import module
sphinx-build fail - autodoc can't import/find module @ryandillan suggestion to add sys.path.insert(0, os.path.abspath('..'))
to config.py
fixed my 404 "index not found" error for model index
for index.rst
sphinx-build 失败 - autodoc 无法导入/找到模块@ryandillan 建议将
sys.path.insert(0, os.path.abspath('..'))
到config.py
修复了我的404“未找到索引” index.rst
model index
错误
I have added extensions = ['sphinx.ext.autodoc']
to config.py
as recommend in another stackoverflow thread.我已按照另一个 stackoverflow 线程中的建议将
extensions = ['sphinx.ext.autodoc']
到config.py
。
Any suggestions on what else I am doing incorrectly?关于我做错了什么的任何建议?
Based on your directory structure, the directory to add to sys.path
should be ../src
根据您的目录结构,添加到
sys.path
的目录应该是../src
For a more general answer, think about what directory you would need to be in if you wanted to import module
successfully in the Python CLI.有关更一般的答案,请考虑如果您想在 Python CLI 中成功
import module
您需要位于哪个目录中。 That directory is the one you want Sphinx to have in your path.该目录是您希望 Sphinx 在您的路径中拥有的目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.