-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)

1
  • What is "image"? You import image, do you mean PIL.Image? 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". Commented Nov 20, 2016 at 23:03

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

5 Comments

This code will not run, as the path is unquoted and thus not recognized as string.
Well I am sorry, it was a fail. But at least i put the source where i get the code, not like the other comments. But I see you only you just look at me.
You may just edit your answer to make it correct.
I know. Hope you comment on all like you do with me ;)
This has nothing to do with you. I'm just making sure there are not false solutions around which may then cause confusion when other people copy the answer and get errors again.
0

Try this:

from PIL import Image

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

im.show()

Comments

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()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.