gpt4 book ai didi

python - Doctest 在 Sphinx 中不起作用,无法导入 python 文件 Python

转载 作者:行者123 更新时间:2023-12-05 05:38:55 25 4
gpt4 key购买 nike

我在尝试从 Sphinx Tutorial 运行 doctest 时遇到问题.我有下面的目录树,但我无法为 lumache.py 运行 doctest。如何才能使 lumache.py 可以通过 conf.py 中的 pathlib 函数导入,这是 sys. path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix())。我要执行的代码与教程中的代码相同(超链接在第一句话)。

conf.py 内容

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here.
import pathlib
import sys
sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix())

extensions = [
'sphinx.ext.duration',
'sphinx.ext.doctest',
]

...

内容 lumache.py

def get_random_ingredients(kind=None):
return ["shells", "gorgonzola", "parsley"]

命令执行

C:\docs>make doctest
ModuleNotFoundError: No module named 'lumache'

目录树:

docs/
├─build/
│ ├─doctest/
│ │ └─0 folder(s), 1 file(s)
│ ├─doctrees/
│ │ └─0 folder(s), 3 file(s)
│ └─html/
│ └─3 folder(s), 7 file(s)
├─make.bat
├─Makefile
└─source/
├─conf.py
├─index.rst
├─lumache.py
├─usage.rst
├─_static/
│ └─0 folder(s), 0 file(s)
└─_templates/
└─0 folder(s), 0 file(s)

最佳答案

lumache.py 移动到您的项目文件夹(即与 docs/ 当前所在的文件夹相同)。

关于python - Doctest 在 Sphinx 中不起作用,无法导入 python 文件 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72822783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com