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

Time:09-04

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.

CodePudding user response:

You can use relative path syntax.

If you move the image into the parent directory you can prefix it with .. which means "up one directory".

![imagetest.png](../imagetest.png)

If you move it to a subdirectory, you should be able to prefix it with the path to that subdirectory.

![imagetest.png](sub/directory/path/imagetest.png)

CodePudding user response:

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

  • Related