Skip to main content
 首页 » 编程设计

python之是否可以在 Python 中将图片嵌入到文档字符串中

2025年05月04日38pander-it

是否可以在 Python 中将图片嵌入到文档字符串中?

我在某处看到了 docpicture 关键字,但在上面找不到 doc。是刺还是不刺?

图片应该放在哪里?

更新

我尝试了 Sphinx 表示法,但我的 PyCharm 显示

即它看到这里应该是一张图片,但没有看到图片文件。

如果使用 Sphinx,我会放在哪里?

请您参考如下方法:

这取决于您使用什么工具来处理您的文档字符串。查看工具的文档以了解如何嵌入图像。

例如,如果您使用的是 Sphinx,则可以使用 image 指令,如 this StackOverflow answer 中所述。 :

.. image:: example.png 

关于图像的位置,documentation状态:

When used within Sphinx, the file name given [...] must either be relative to the source file, or absolute which means that they are relative to the top source directory. For example, the file sketch/spam.rst could refer to the image images/spam.png as ../images/spam.png or /images/spam.png.