【问题标题】:Insert image (in the same folder as the notebook) in a text cell of the notebook with Colaboratory使用 Colaboratory 在笔记本的文本单元格中插入图像(与笔记本在同一文件夹中)
【发布时间】:2019-01-31 09:12:30
【问题描述】:

我使用 Colaboratory 在笔记本上工作,我尝试在文本单元格中插入与笔记本存储在同一文件夹中的图片。

我试过了:![](image.png)<img src="image.png" />

甚至![](./image.png)<img src="./image.png" />

但它不起作用。

【问题讨论】:

    标签: jupyter-notebook jupyter google-colaboratory jupyter-lab


    【解决方案1】:

    您正在尝试使用相对路径,但这不是 colab markdown 单元格的工作方式。 内嵌图片只能引用公开可读的(绝对)网址。

    【讨论】:

      【解决方案2】:

      这是一个技巧

      path = '/usr/local/share/jupyter/nbextensions/google.colab'
      !cp -r {path}/* .
      !rm -r {path}
      !ln -s /content {path}
      # change base tag
      from google.colab.output import eval_js
      def change_base_url():
        eval_js("""
        var base = document.createElement('base')
        base.href = 'https://localhost:8080/nbextensions/google.colab/'
        document.head.prepend(base)
        """)
      # make it run automatically in every cell
      get_ipython().events.register('pre_run_cell', change_base_url)
      

      它将google.colab 目录与/content 合并。然后将输出帧的基本路径改为/nbextensions/google.colab

      这是一个示例笔记本

      https://colab.research.google.com/drive/1AX30RdTRNdrhu6qDZd-5ptlsgnTSTFAu

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-03
        • 1970-01-01
        • 1970-01-01
        • 2017-08-04
        • 2013-09-05
        • 2021-01-11
        • 2016-01-14
        • 1970-01-01
        相关资源
        最近更新 更多