问题描述
此代码,不显示图像:
plt.imshow(Image.open(img_paths[0]))
也许我需要专业版?
推荐答案
以下代码在 PyCharm 中有效.图像显示在新窗口中.我将名为 image.png 的图像复制到我的 PyCharm 项目的 venv 文件夹中,以便 PyCharm 可以自动找到它.您可以对名为 img_paths 的列表执行相同操作,而不是将名为 image.png 的图像粘贴到 PyCharm 项目的 venv 文件夹中.
The following code works in PyCharm. The image is displayed in a new window. I copied my image named image.png into my PyCharm project's venv folder so that PyCharm would find it automatically. Instead of pasting an image named image.png into your PyCharm project's venv folder, you could do the same with your list named img_paths.
import matplotlib.pyplot as plt
from PIL import Image
fname = 'image.png'
plt.imshow(Image.open(fname))
plt.show()
注意:除非已将项目配置为可以查找,否则PyCharm不会自动查找您全局安装的Python软件包.为此,在创建新项目时选择继承全局站点包选项.
Note: PyCharm does not automatically find your globally installed Python packages unless the project has been configured to find them. To do this select the Inherit global-site packages option when you create a new project.
选择文件-> 新项目创建一个新项目.单击下面屏幕截图中鼠标光标标记的三角形以显示新项目的选项.
Select File -> New Project to create a new project. Click the triangle marked by the mouse cursor in the below screenshot to show the new project's options.
然后选中继承全局站点包复选框,然后单击创建项目"窗口右下角的按钮.
Then check the Inherit global-site packages checkbox and click the button in the lower right corner of the Create Project window.
这篇关于Pycharm 不显示图像(matplotlib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!