1

Edit: It might help to know that I'm using python 2.7.9 (that's what was taught in my GIS class). I've almost got it working I think. Although now it's a new question. I have this code

from PIL import Image
im = Image.open("C:/users/Chrostopher/Asuna.png")

There are no error messages and my screen flashed black like it wanted to do something, but the picture didn't show/open/display. What should I do?

Thanks for all the help so far. I feel like I'm slowly (and with many mistakes) learning something useful. Old: I am very, very new at this, which is why I'm asking. I've looked around for help, but there's always one thing I don't understand and it's just turned into a very deep rabbit hole. When I've tried the code I've seen here, it doesn't work. Looking further, I need the Python Image Library (PIL). I've downloaded it, but I can't figure out how to set it up to work in Python. The file is a .gz. Is there some place I need to put the file or some way to import it? If you could answer step by step, that would be wonderful for this extreme newb.

This is the code I have (to try and open an image which is the end goal)

import Image
def main():
    filename = "desert.jpg"
    image = Image.open(filename)
    image.show
    del image

if (__name__ == "__main__"):
    main()

Is there something I'm missing or not doing right that is messing up what I'm trying to do?

  • 1
    If you install 'pip', you can use this package manager to install python libraries. Your system may already have it – tom Mar 27 '15 at 19:54
  • Here is a tutorial for installing Python packages. See the pip + virtual environments part: https://packaging.python.org/en/latest/installing.html#creating-virtual-environments – Mikko Ohtamaa Mar 27 '15 at 19:56
  • You've unzipped the `.gz` file, right? That's step 1... – kindall Mar 27 '15 at 19:57
  • 1
    This has nothing to do with import libraries, but image.show without paranthesis doesn't do anything ... you almost certainly want image.show() Also, you don't need to use del 99.99% of the time. Python isn't C. – Foon Mar 27 '15 at 20:07

1 Answers1

0

First install Pillow with "pip"

$ pip install Pillow

Then, instead writing

import Image

In the first line, you can use:

from PIL import Image
hft
  • 1,245
  • 10
  • 29
  • Assuming they're using Pillow and not PIL. – jedwards Mar 27 '15 at 19:55
  • I did this `code` from PIL import Image im = Image.open("C:/users/Chrostopher/Asuna.png") and it's almost working see the edited main description for the problem. Thanks for the help so far. – tictacattack Apr 03 '15 at 06:41
  • I have this `code` from PIL import Image im = Image.open("C:/users/Chrostopher/Asuna.png") end`code` When I ran the code, there were no error messages and my screen flashed black like it wanted to do something, but the picture didn't show/open/display. Any suggestions on what I'm doing wrong or need to do? – tictacattack Apr 03 '15 at 06:57
  • Maybe the image is flashing up very fast and then the program is exiting. At the beginning of the file add a new line that reads "from time import sleep". After the line with Image.open add a new line that reads "sleep(5)". This will pause your code for 5 seconds so you can see if the image really opened or not. – hft Apr 03 '15 at 07:08
  • Hm, it only flashed black the first time I ran the code (without your fixes), now it just pauses 5 seconds (which is good to know, thanks). Do I need to have something to allow it to display? I'm working in the shell btw, not an .exe if that makes a difference. – tictacattack Apr 03 '15 at 07:17
  • I added im.show() after im = Image.open(filename) and that worked. It opened in windows photo viewer (which is the default program I have set). Thanks for all the help. – tictacattack Apr 03 '15 at 07:23