【问题标题】:Image (GIF) not displaying图片 (GIF) 不显示
【发布时间】:2020-02-14 06:10:12
【问题描述】:

使用 colab (python),可视化未确认的行星物体;有时候是这样的!我不明白!请帮助...这是我的代码 https://colab.research.google.com/github/spacetelescope/notebooks/blob/master/notebooks/MAST/TESS/interm_tesscut_dss_overlay/tesscut_dss_overlay.ipynb#scrollTo=hNBL87NF9Wml&uniqifier=1

有问题的代码:

 #display the gif

if not os.path.exists(gif):
    print("No gif found. Cannot display gif of time-series.")

Image(gif, embed=True)

错误日志:

ValueError                                Traceback (most recent call last) <ipython-input-27-d599e0c825fd> in <module>()
      2     print("No gif found. Cannot display gif of time-series.")
      3 
----> 4 Image(gif, embed=True)

/usr/local/lib/python3.6/dist-packages/IPython/core/display.py in
__init__(self, data, url, filename, format, embed, width, height, retina, unconfined, metadata)    1013     1014         if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS:
-> 1015             raise ValueError("Cannot embed the '%s' image format" % (self.format))    1016         self.width = width    1017    self.height = height

ValueError: Cannot embed the 'gif' image format

【问题讨论】:

  • 你能透露一下你使用的是哪个包用于 Image()
  • 您的图片是否有扩展名“.gif”但它实际上不是 GIF?检查file 对此有何评论(如果您使用的是 Linux/OS X 系统),或者使用十六进制查看器打开文件并检查其第一个字节是否包含正确的魔法签名。

标签: python google-colaboratory


【解决方案1】:

而不是嵌入文件路径:

Image(gif, embed=True)

您可以直接嵌入图像字节:

Image(open(gif, 'rb').read())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-13
    • 2012-10-23
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 1970-01-01
    相关资源
    最近更新 更多