【问题标题】:Unable to display IPython object in ubuntu, but displayed in colab output无法在 ubuntu 中显示 IPython 对象,但在 colab 输出中显示
【发布时间】:2021-06-20 20:02:05
【问题描述】:

我在“test”文件夹中有一堆图像,我在一个文件中有一个 python 代码来显示这些图像。这是代码

import torch
from IPython.display import Image, clear_output
import matplotlib
import glob
import PIL
from IPython.display import Image, display
from io import BytesIO

print("hi")
for imageName in glob.glob('test/images/*.jpg'): #assuming JPG
  print("in \n")
  display(Image(filename=imageName)) #displaying successfully in colab
  print("out")
  print("\n")

这是我在 ubuntu 终端中运行 python 文件时的输出。

我没有打开其他选项卡来显示图像图像。我在堆栈溢出中尝试了其他答案,但没有奏效。但是,这些图像在 colab 的输出中是可见的。

【问题讨论】:

  • 这篇文章可能对stackoverflow.com/a/52627121/13273054有帮助
  • @WaveShaper 我看过那篇文章,但对我没有帮助。当我在终端中运行它时,我可以在 colab 的输出中看到图像,但在 ubuntu 中看不到。

标签: python image ubuntu ipython display


【解决方案1】:

您在终端中运行,终端只能显示文本。 因此display(Image(...)) 无法显示您的图像。

displayImage 是真正以 IPython/Jupyter 为中心的实用程序,在使用纯 Python 时无法完全运行。

如果您想在终端中运行时显示图像,您需要使用pillowmatplotlib 之类的东西,并要求他们打开一个带有图像的新窗口,根据您的操作方式,您可以程序需要关闭窗口才能继续执行。

您也可以在本地运行jupyter notebook(或jupyter lab)来打开应支持图像的网络界面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 2022-09-25
    • 1970-01-01
    相关资源
    最近更新 更多