python - 无法在 ubuntu 中显示 IPython 对象,但在 colab 输出中显示

标签 python image ubuntu ipython display

我在“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 文件时的输出。
Terminal output ss of code
我没有打开其他选项卡来显示图像图像。我在堆栈溢出中尝试了其他答案,但没有奏效。但是,这些图像在 colab 的输出中是可见的。

最佳答案

您在终端中运行,终端只能显示文本。
因此display(Image(...))无法显示您的图像。displayImage是真正以 IPython/Jupyter 为中心的实用程序,在使用纯 Python 时无法完全运行。
如果你想在终端运行时显示图像,你需要使用 pillow 之类的东西。或 matplotlib并要求他们打开一个带有图像的新窗口,根据您的操作方式,您可能需要关闭窗口以使程序继续执行。
也可以在本地运行jupyter notebook (或 jupyter lab )打开应支持图像的 Web 界面。

关于python - 无法在 ubuntu 中显示 IPython 对象,但在 colab 输出中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66775474/

相关文章:

c++ - 在 OpenCV 中寻找轮廓?

css - 用于锐化图像的怪异 CSS hack(仅限 Chrome 59 和 60)

java - XML 图片更改

ubuntu - 连接到 WordPress Docker 容器

ubuntu - 无法在 Web 浏览器中显示 Unicode 字符?

python - 在 Python Tools for Visual Studio (PTVS) 中调试 python 代码时如何抑制控制台窗口?

python - 如何在没有强类型的情况下确保可靠的合约?

python - Pandas 可以在 Google App Engine for Python 上运行吗?

python - 如何选择列表中多次出现的任意数量的元素?

mongodb - monit 无法读取 mongod.lock