简体   繁体   English

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

[英]FileNotFoundError: [Errno 2] when using sphinx and autodoc

I am trying to use sphinx to run an autodoc.我正在尝试使用 sphinx 来运行自动文档。 My project structure like this:我的项目结构是这样的:

在此处输入图像描述

Where the python files are reading from input/input.xlsx . python 文件从input/input.xlsx读取的位置。 My conf.py looks like:我的conf.py看起来像:

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

extensions = ['sphinx.ext.autodoc']

I run the ./docs/sphinx-apidoc -o./source../ where it creates a:我运行./docs/sphinx-apidoc -o./source../它创建一个:

module.rst模块.rst

and:和:

My_Project.rst My_Project.rst

inside the ./docs/source ../docs/source中。

My issue is that when I build the make html , it gives me errors like:我的问题是,当我构建make html时,它给了我如下错误:

FileNotFoundError: [Errno 2] No such file or directory: './input' FileNotFoundError:[Errno 2] 没有这样的文件或目录:'./input'

However, as I have set in conf.py , it should logically go two levels high and one level down to /input folder.但是,正如我在conf.py中设置的那样,它在逻辑上应该是 go 高两层,低一层到/input文件夹。

../../input ../../输入

Appreciate any ideas.欣赏任何想法。

Finally I figured out something that worked for me.最后我想出了一些对我有用的东西。 Beforehand, I need to clarify something: in one of python files located in ../../ from my source directory, the code is reading an excel file from this path ./input/input.xlsx .事先,我需要澄清一些事情:在我的source目录中位于../../的 python 文件之一中,代码正在从此路径./input/input.xlsx读取 excel 文件。 I figured out that defining a hard coded path is the source of this issue.我发现定义硬编码路径是这个问题的根源。 So I fixed it with following code:所以我用以下代码修复了它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM