FileNotFoundError:使用sphinx和autodoc时出现[Errno 2]

时间:2019-11-14 02:24:51

标签: python python-sphinx autodoc

我正在尝试使用sphinx创建自动文档。我的项目结构如下:

enter image description here

python文件从input / input.xlsx读取的位置。 我的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:[错误2]没有这样的文件或目录:'./input'

但是,正如我在conf.py中设置的那样,它在逻辑上应该升到两级,然后再降到/input文件夹。

  

../../ input

赞赏任何想法。

1 个答案:

答案 0 :(得分:1)

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

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