2

I've tried to import a png file in Python 3.6 with Jupyter Notebook with no success. I've seen some examples that don't work, at least not anymore, i.e.

 import os,sys
 import Image
 jpgfile = Image.open("picture.jpg")

There is no module called Image that I can install with either: conda install Image or pip install Image

Any simple solution would be greatly appreciated!

MichaelRSF
  • 886
  • 5
  • 16
  • 40
  • look here: https://stackoverflow.com/questions/32370281/how-to-include-image-or-picture-in-jupyter-notebook/32370538#32370538 – Reblochon Masque Aug 29 '17 at 00:30
  • Possible duplicate of [How to Include image or picture in jupyter notebook](https://stackoverflow.com/questions/32370281/how-to-include-image-or-picture-in-jupyter-notebook) – Reblochon Masque Aug 29 '17 at 00:30
  • Thanks for the response, Reblochon. However, I'm trying to import images using Python in any IDE, I just happen to be using Jupyter Notebook. I've looked at the links, and they were only for importing images from websites. I'd like to import a saved png file from a folder. And not using Markdown. I'm surprised trying to find the solution is so ambigious :/ – MichaelRSF Aug 29 '17 at 00:44

1 Answers1

1

You can display an image from file in a Jupyter Notebook as follows:

from IPython.display import Image
img = 'fig31_Drosophila.jpg'
Image(url=img)

where img = 'fig31_Drosophila.jpg' is the path and filename of the image you want. (here, the image is in the same folder as the main script)

alternatively:

from IPython.display import Image
img = 'fig31_Drosophila.jpg'
Image(filename=img)

You can specify optional args (for width and height for instance:

from IPython.display import Image
img = 'fig31_Drosophila.jpg'
Image(url=img, width=100, height=100)
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
  • 1
    Thank you, much appreciated Reblochon! I managed to finally get it to work. I kept getting a broken image output. I had to make sure the file path was correct. `from IPython.display import Image`, `img = "C:/Users/Michael/Call_Options_Graphv_1.jpg"`, `Image(url=img)` – MichaelRSF Aug 29 '17 at 01:03