-1

I am trying to display a .jpg image using Python.

I have tried this:

import image

image=image.open(C:\Users\Me\Desktop\image.jpg)

  image.show()

I thought typing the path in the () will import the image. Where must I save the image for this to work or what must I write to be able to import an image from anywhere(for example the desktop)

sorin
  • 161,544
  • 178
  • 535
  • 806
  • What is "image"? You import `image`, do you mean [`PIL.Image`](http://pillow.readthedocs.io/en/3.4.x/reference/Image.html)? In any case after that you assign the opened picture to `image`, which is bad because you have lost your imported module named `image` (while in this case it'll still work, you shouldn't do that). Last, your path needs to be given in quotes `"path\to\file.jpg"`. – ImportanceOfBeingErnest Nov 20 '16 at 23:03

3 Answers3

1

You can try installing PIL package.

from PIL import Image                                                                                
 img = Image.open("C:\Users\Me\Desktop\image.jpg")
 img.show() 

Source:Showing an image from console in Python

Community
  • 1
  • 1
Roberto García
  • 115
  • 1
  • 11
0

Try this:

from PIL import Image

im = Image.open("image.jpg") #path

im.show()
AlexDotis
  • 324
  • 4
  • 11
0

Go to command prompt if you are in windows and pip install pillow to get the PIL and then try the code below. If it is in your desktop just mention your file name and .jpg or .png as the path. It should open in your default image viewer.

from PIL import Image
img=Image.open("icon.png")
img.show()
ash95onit
  • 11
  • 1
  • 5