Sphinx 发出警告,因为它找不到导入的文件
Sphinx gives warning as it cannot find imported file
我正在尝试生成文档,但 运行 在命令行中出现警告。我一直在搜索该站点,但找不到适合我的工作解决方案。我将原因缩小到 ClassB 中的导入。
我的文件夹结构是:
__init__.py
个文件没有内容。
classA.rst:
classA
======
.. automodule:: app.ClassA
:members:
classB.rst:
classB
======
.. automodule:: app.ClassB
:members:
index.rst(仅限目录树):
.. toctree::
:maxdepth: 2
:caption: Contents:
classA
classB
conf.py(仅路径):
sys.path.insert(0, os.path.abspath('../src'))
ClassA.py:
class A:
def sayNo(self):
print('NO!')
ClassB.py:
from ClassA import A
class B:
def sayNoB(self):
no = A()
no.sayNo()
来自命令行的警告:
WARNING: autodoc: failed to import module 'ClassB' from module 'app'; the following exception was raised:
No module named 'ClassA'
至于我,你应该使用相对导入 - dot
from .ClassA import A
我正在尝试生成文档,但 运行 在命令行中出现警告。我一直在搜索该站点,但找不到适合我的工作解决方案。我将原因缩小到 ClassB 中的导入。
我的文件夹结构是:
__init__.py
个文件没有内容。
classA.rst:
classA
======
.. automodule:: app.ClassA
:members:
classB.rst:
classB
======
.. automodule:: app.ClassB
:members:
index.rst(仅限目录树):
.. toctree::
:maxdepth: 2
:caption: Contents:
classA
classB
conf.py(仅路径):
sys.path.insert(0, os.path.abspath('../src'))
ClassA.py:
class A:
def sayNo(self):
print('NO!')
ClassB.py:
from ClassA import A
class B:
def sayNoB(self):
no = A()
no.sayNo()
来自命令行的警告:
WARNING: autodoc: failed to import module 'ClassB' from module 'app'; the following exception was raised:
No module named 'ClassA'
至于我,你应该使用相对导入 - dot
from .ClassA import A