python - Sphinx 发出警告,因为它找不到导入的文件
问题描述
我正在尝试生成文档,但在命令行中遇到警告。我一直在搜索该站点,但找不到适合我的解决方案。我将原因缩小到 ClassB 中的导入。
我的文件夹结构是:
__init__.py
文件没有内容。
类A.rst:
classA
======
.. automodule:: app.ClassA
:members:
类B.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'))
类A.py:
class A:
def sayNo(self):
print('NO!')
B类.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
推荐阅读
- c - 为什么在使用 isdigit 函数时出现分段错误?
- spring-boot - Spring Boot 2.5 Hibernate 错误:无法获取当前线程的事务同步会话
- python - 在文本字段中输入文本后如何按 Enter?
- python - 使用 python 将 csv 文件加载到 SnowFlake 表中
- spring-boot - 如何使 Spring Boot 适配器中的 Keycloak 策略执行器与 vaadin 一起使用
- apache - Apache 反向代理到动态端口
- c - 从北欧半导体库了解编写预处理器指令的方法
- ssl - 如何根据请求域动态设置 SSL 证书?
- azure - Bot Composer - QNA Intent 得到认可
- math - 这个后缀表达式在中缀中会是什么?