gpt4 book ai didi

python - FileNotFoundError : [Errno 2] when using sphinx and autodoc

转载 作者:行者123 更新时间:2023-12-01 04:25:34 34 4
gpt4 key购买 nike

我正在尝试使用 sphinx 运行 autodoc。我的项目结构是这样的:

enter image description here

input/input.xlsx 读取 python 文件的位置.
我的 conf.py好像:

import os 
import sys
sys.path.insert(0, os.path.abspath('../../'))

extensions = ['sphinx.ext.autodoc']

我运行 ./docs/sphinx-apidoc -o ./source ../它创建了一个:

module.rst



和:

My_Project.rst



./docs/source .

我的问题是,当我构建 make html 时,它给了我这样的错误:

FileNotFoundError: [Errno 2] No such file or directory: './input'



但是,正如我在 conf.py 中设置的那样,从逻辑上讲,它应该上升两级,下降一级至 /input文件夹。

../../input



欣赏任何想法。

最佳答案

最后我想出了一些对我有用的东西。事先,我需要澄清一些事情:在位于 ../../ 的 python 文件之一中。来自我的 source目录,代码正在从这个路径读取一个 excel 文件 ./input/input.xlsx .我发现定义硬编码路径是这个问题的根源。所以我用以下代码修复了它:

directory_path = os.path.dirname(os.path.abspath(__file__)) 
new_path = os.path.join(directory_path, "input.xlsx")

关于python - FileNotFoundError : [Errno 2] when using sphinx and autodoc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58848486/

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