狮身人面像找不到我的项目的根模块



我有这个示例项目来学习狮身人面像是如何工作的。

目录结构如下:

.
+--app
|  +--api
|     +--endpoints
|        +--address.py
|
|--docs
|  +--conf.py
|  +--index.rst
|  +--source
|     +--modules.rst
|     +--address.rst

我在conf.py中的路径中添加了相关的文件路径,如下所示:

import os
import sys
from pathlib import Path
project_root = Path(os.getcwd()).parent.absolute()
sys.path.insert(0, project_root)
path_app = os.path.join(project_root, "app")
sys.path.insert(0, path_app)
path_address = os.path.join(project_root, "app", "api", "endpoints")
sys.path.insert(0, path_address)

我有我的/docs/index.rst文件,由Sphinx:自动生成

.. Sky-Payment documentation master file, created by
sphinx-quickstart on Fri Apr 16 17:23:31 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Sky-Payment's documentation!
=======================================
.. toctree::
:maxdepth: 2
:caption: Contents:

Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

然后我有我的docs/source/modules.rst文件:

app
===
.. toctree::
:maxdepth: 4
address

和我的docs/source/address.rst文件:

address module
==============
.. automodule:: app.api.endpoints.address
:members:
:undoc-members:
:show-inheritance:

当我从.docs运行sphinx-build.exe -b html . ._build时,我会得到以下错误:

WARNING: autodoc: failed to import module 'api.endpoints.address' from
module 'app'; the following exception was raised: No module named
'app'

我在这里做错了什么?

conf.py中,放入sys.path.insert(0, "..")/相对路径导航到父目录。由于conf.py位于docs/中,因此documents/

相关内容

  • 没有找到相关文章

最新更新