经过多次搜索和尝试,我还没有找到解决这个问题的方法......
我正在使用 Sphinx 为 Python 包生成文档。您可以在此处查看代码:https ://github.com/jajimer/energym/tree/documentation 。我们感兴趣的包部分组织如下:
在energym/docs/source/conf.py
我配置的路径如下:
import os
import sys
sys.path.insert(0, os.path.abspath('../../energym/'))
现在我正在尝试将这个模块及其所有组件energym/doc/source/pages/API-reference.rst
的描述添加到 API 文档 () 中。utils
为此,我正在使用 Sphinx 的autosummary
:
.. autosummary::
:toctree: modules
:template: custom-module-template.rst
:recursive:
utils
所以,在做完之后,和make clean && make html
的文档是完美创建的,但不是. 根据 Sphinx 的说法,会发生以下异常:utils.common
utils.rewards
utils.rewards
utils.controllers
File "/home/user/projects/energym/energym/utils/controllers.py", line 8, in <module>
from ..utils.common import parse_variables
ValueError: attempted relative import beyond top-level package
这是我的问题。我该如何解决?是相对路径问题吗?我已经看到问题是由于以下导入引起的:
from ..utils.common import parse_variables
但我真的不知道原因,因为路径似乎很完美。