pythonimagejupyter-notebookattachment

How to attach an image in Jupyter Notebook without keeping the file in the same directory?


I'm trying to use Jupyter Notebook in VS Code (but tested the same thing in Jupyter on browser, and didn't work as well).

If I put the image file in the same directory of the ipynb file, I can drag and drop using the code below, and it works:

![](imagetest.png)

But if I move the image file to other directory, or delete it, the image doesn't appear anymore.

I tried to use:

![imagetest.png](attachment:imagetest.png)

as I saw in others examples (which was working fine), but when I try the same, it doesn't work.

I want to attach the image in ipynb file and make it independent of the source image file, as I can do in a MS Word file, for example.


Solution

  • First try copying the image and pasting it, run the cell and see if it works. If it works, it will work every time. After pasting the picture the code looks like this:-

    ![image.png](attachment:image.png)
    

    Next, Run the cell and it will be inserted.

    Pic of pasting picture:- https://i.stack.imgur.com/XI4Il.png

    Pic of picture inserted:- https://i.stack.imgur.com/DFA4O.png

    Picture added

    Pasting picture