我在从Sphinx Tutorial开始跑doctest时遇到了问题.我有下面的目录树,但我不能运行doctest for lumache.py.如何才能使lumache.py可以导入conf.py中的pathlib函数,即sys.path.insert(0, pathlib.Path(__file__).parents[2].resolve().as_posix()).我试图执行的代码与教程中的代码相同(第一句中提到了超链接).

conf.py Contents

# 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',
]

...

Contents of lumache.py

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

CMD execution

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

Directory Tree:

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相关问答推荐

韦尔福德方差与Numpy方差不同

删除任何仅包含字符(或不包含其他数字值的邮政编码)的观察

追溯(最近最后一次调用):文件C:\Users\Diplom/PycharmProject\Yolo01\Roboflow-4.py,第4行,在模块导入roboflow中

在Google Colab中设置Llama-2出现问题-加载判断点碎片时Cell-run失败

用Python解密Java加密文件

组/群集按字符串中的子字符串或子字符串中的字符串轮询数据框

在ubuntu上安装dlib时出错

为什么np. exp(1000)给出溢出警告,而np. exp(—100000)没有给出下溢警告?

将scipy. sparse矩阵直接保存为常规txt文件

python中csv. Dictreader. fieldname的类型是什么?'

Pandas:计算中间时间条目的总时间增量

具有相同图例 colored颜色 和标签的堆叠子图

为什么在FastAPI中创建与数据库的连接时需要使用生成器?

使用tqdm的进度条

在电影中向西北方向对齐""

使用np.fft.fft2和cv2.dft重现相位谱.为什么结果并不相似呢?

对包含JSON列的DataFrame进行分组

删除另一个div中的特定div容器

将索引表转换为Numy数组

简化通用属性的创建