Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python FileNotFoundError:[Errno 2]在使用sphinx和autodoc时_Python_Python Sphinx_Autodoc - Fatal编程技术网

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

Python FileNotFoundError:[Errno 2]在使用sphinx和autodoc时,python,python-sphinx,autodoc,Python,Python Sphinx,Autodoc,我正在尝试使用sphinx运行autodoc。我的项目结构如下: 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../,它在其中创建一个: 模块rst 以及: 我的计划 在

我正在尝试使用sphinx运行autodoc。我的项目结构如下:

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../
,它在其中创建一个:

模块rst

以及:

我的计划

/docs/source

我的问题是,当我构建
生成html
时,它会给我以下错误:

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

但是,正如我在
conf.py
中设置的那样,它在逻辑上应该达到两个级别,一个级别下降到
/input
文件夹

../../input


谢谢你的建议。

我终于想出了一个适合我的办法。在此之前,我需要澄清一点:在我的
源代码
目录中位于
。/../
的一个python文件中,代码正在从路径
/input/input.xlsx
读取一个excel文件。我发现定义硬编码路径是这个问题的根源。所以我用以下代码修复了它:

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

@糟糕的编码器。是的,我也这么做了。但这完全破坏了代码,并导致了新的错误,因为其他文件位于相对路径中。最后我找到了一个适合我的方法。但在我需要澄清之前,在
。/../
中的一个文件中,代码正在从路径
/input/input.xlsx
读取excel文件。下面的代码解决了我的问题:
directory\u path=os.path.dirname(os.path.abspath(\uu文件\uuuu))new\u path=os.path.join(directory\u path,“input.xlsx”)