Sphinx autodoc无法导入modu

2024-09-29 20:23:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Sphinx来记录一个项目,但遇到了一个问题,即只有一些模块是从文件夹中导入的。我的项目结构如下:

Project
|
|--Main
|    |--Scripts
|          __init__.py
|          libsmop.py
|          conv_table.py
|          f_discrim.py
|          recipes.py
|          ...

当我尝试运行make html时,libsmop和{}被导入而没有任何问题,但是conv_table和{}得到以下错误:

WARNING: autodoc: failed to import module u'conv_table' from module u'Scripts'; the following exception was raised:No module named conv_table

我不认为这是我的配置文件,因为当我运行sphinx-apidoc -o _rst Main/Scripts时,它会找到所有的文件,并且我已经确认它们出现在生成的Scripts.rst文件中。在

为什么autodoc会找到一些模块而不是其他模块?在

编辑: conv_table.py的形式是:

^{pr2}$

Tags: 模块文件项目pymainsphinx记录table
1条回答
网友
1楼 · 发布于 2024-09-29 20:23:34

您需要根据Sphinx docs检查模块加载路径:

For Sphinx (actually, the Python interpreter that executes Sphinx) to find your module, it must be importable. That means that the module or the package must be in one of the directories on sys.path – adapt your sys.path in the configuration file accordingly.

另外,了解脚本目录中的__init__.py是什么样子,以及conv_table模块是什么样子,这也是很有用的。在

相关问题 更多 >

    热门问题