tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Trouble installing Pillow / PIL

Thu Jun 12, 2014 11:24 am

Hey,
I am new to Raspberry Pi and the terminal. I want to write a simple python program that can display a JPEG but I am having issues downloading/installing PIL (Python Imaging Library)/Pillow. I tried to do sudo apt-get and it says it is done but then it doesn't work. I also tried downloading the module and saving the files but now how do I actually install it?

DirkS
Posts: 7415
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Trouble installing Pillow / PIL

Thu Jun 12, 2014 1:41 pm

I tried to do sudo apt-get and it says it is done but then it doesn't work.
What was the exact command you used for installation?
How did you try to use it?
Did you get any error messages?

Gr
Dirk.

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Tue Jul 01, 2014 12:12 pm

I found out that I couldn't run the "setup.py" file that comes in PIL because I didn't have the Setuptools module installed properly. I vaguely remember getting an error when I had done:

Code: Select all

 sudo apt-get install python-dev python-setuptools 
What should I do to fix that? Should I just try downloading it again?

Also, is there a specific place that I should have saved the Pillow-2.3.0 module file? I have it currently saved inside /home/pi and am not sure if this could be contributing to the problem that I am having.

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Tue Jul 01, 2014 12:19 pm

DirkS wrote: How did you try to use it?
I was trying to do something like:

Code: Select all

from PIL import image
global ext
ext = ".jpg"
imageFile = "test.jpg"
img = Image.open(imageFile) 
or something like:

Code: Select all

import Image 
img = Image.open("test.jpg")
img.save("test.png")
img.show()

DirkS
Posts: 7415
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Trouble installing Pillow / PIL

Tue Jul 01, 2014 5:19 pm

tm48 wrote:I found out that I couldn't run the "setup.py" file that comes in PIL because I didn't have the Setuptools module installed properly. I vaguely remember getting an error when I had done:

Code: Select all

 sudo apt-get install python-dev python-setuptools 
What should I do to fix that? Should I just try downloading it again?
Yes, I would again with installing python-dev and python-setuptools. If you get any error messages you can't resolve just report back here.
Also, is there a specific place that I should have saved the Pillow-2.3.0 module file? I have it currently saved inside /home/pi and am not sure if this could be contributing to the problem that I am having.
IIRC you can put it anywhere, but you have to extract it and then use the setup line you used. The setup will normally take care of the rest. It could be that you have use 'sudo'.

As said, since you don't know what error message you got I would just start from the beginning again.

HTH
Dirk.

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Wed Jul 02, 2014 2:50 pm

Okay so here is what I got:

Code: Select all

pi@raspberrypi ~/Pillow-2.3.0 $ sudo python3 setup.py
Traceback (most recent call last):
  File "setup.py", line 19, in <module>
    from setuptools import Extension, setup, find_packages
ImportError: No module named setuptools
I did this:

Code: Select all

sudo apt-get install python-setuptools 
And I got no errors and it said that its already installed. I don't get why it says there is no module.

DirkS
Posts: 7415
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Trouble installing Pillow / PIL

Wed Jul 02, 2014 3:49 pm

tm48 wrote:

Code: Select all

pi@raspberrypi ~/Pillow-2.3.0 $ sudo python3 setup.py

Code: Select all

sudo apt-get install python-setuptools 
Aha... it seems you're using python 3. It has its own version of the setuptools so you have to use

Code: Select all

sudo apt-get install python3-setuptools
HTH
Dirk.

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Wed Jul 02, 2014 4:20 pm

Great! I downloaded the python3 version of it. And now I got this:
pi@raspberrypi ~/Pillow-2.3.0 $ sudo python3 setup.py
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

User avatar
DougieLawson
Posts: 29347
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Trouble installing Pillow / PIL

Wed Jul 02, 2014 4:25 pm

sudo python3 setup.py install
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Wed Jul 02, 2014 5:46 pm

Great! That seemed to work. Thank you!

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Mon Jul 07, 2014 12:05 pm

So I must have done something wrong because I used this command:
DougieLawson wrote:sudo python3 setup.py install
However, when I tried running my code on IDLE3 it says its invalid. But it runs successfully on IDLE. Should I be concerned about this?

This is the code that I have so far:

Code: Select all

from PIL import Image
global ext

ext = ".jpg"
imageFile = "code.jpg"
iml = Image.open(imageFile)

iml.show()
print iml.format 
I added the last line for debugging because iml.show didn't output anything even though the program ran succesfully. I have read online that apparently I have to download the xv utility for iml.show() to work. Is that right? Or could it be because of my previous issues?

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Trouble installing Pillow / PIL

Tue Jul 08, 2014 12:32 am

tm48 wrote:However, when I tried running my code on IDLE3 it says its invalid. But it runs successfully on IDLE. Should I be concerned about this?
It's hard to tell, without seeing the exact error message... :|

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Tue Jul 08, 2014 8:05 am

AndrewS wrote: It's hard to tell, without seeing the exact error message... :|
It highlights "iml" in

Code: Select all

print iml.format
and a pop up that says invalid syntax comes up.

If I try commenting that out, then I get:
Traceback (most recent call last):
File "/home/pi/testide.py", line 1, in <module>
from PIL import Image
ImportError: No module named PIL

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Trouble installing Pillow / PIL

Tue Jul 08, 2014 12:06 pm

tm48 wrote:
AndrewS wrote: It's hard to tell, without seeing the exact error message... :|
It highlights "iml" in

Code: Select all

print iml.format
and a pop up that says invalid syntax comes up.
That's because in Python3, print is a function rather than a statement, so you'd need to change it to

Code: Select all

print(iml.format)
If I try commenting that out, then I get:
Traceback (most recent call last):
File "/home/pi/testide.py", line 1, in <module>
from PIL import Image
ImportError: No module named PIL
This suggests that using pip3 is more reliable for installing pillow than setuptools is?

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Thu Jul 10, 2014 11:49 am

AndrewS wrote: This suggests that using pip3 is more reliable for installing pillow than setuptools is?
I was following that but got an error when I was downloading this dependency:

Code: Select all

sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev \ libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev
The error I got is
E: Unable to locate package libfreetype6-dev
And then the final install commands on that page are only for Ubuntu. What should I do?

DirkS
Posts: 7415
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Trouble installing Pillow / PIL

Thu Jul 10, 2014 12:04 pm

Remove the backslash from the install command line:

Code: Select all

sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev
and try again.

Gr.
Dirk.

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Thu Jul 10, 2014 12:13 pm

tm48 wrote:
AndrewS wrote: This suggests that using pip3 is more reliable for installing pillow than setuptools is?
I was following that but got an error when I was downloading this dependency:

Code: Select all

sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev \ libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev
The error I got is
E: Unable to locate package libfreetype6-dev
Nevermind, I got those to work when I downloaded them individually. Now, my problem is just with these commands:
Install Pillow
For Ubuntu 13.10+: sudo pip3 install Pillow
and for 13.04-: sudo pip-3.2 install Pillow
I get an error: Invalid operation pip3

[/quote]

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Trouble installing Pillow / PIL

Thu Jul 10, 2014 1:26 pm

tm48 wrote:Now, my problem is just with these commands:
Install Pillow
For Ubuntu 13.10+: sudo pip3 install Pillow
and for 13.04-: sudo pip-3.2 install Pillow
I get an error: Invalid operation pip3
After doing 'sudo apt-get install python3-pip' on Raspbian, I then have a pip-3.2 command available... :?:

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Mon Jul 14, 2014 9:36 am

AndrewS wrote: After doing 'sudo apt-get install python3-pip' on Raspbian, I then have a pip-3.2 command available... :?:
That worked! Now I have this code in IDLE3 that compiles but doesn't show me the image:

Code: Select all

from PIL import Image
global ext

ext = ".jpg"
imageFile = "blah.jpg"
iml = Image.open(imageFile)

iml.show()
print(iml.format, iml.size)
Should I use a different program to ran it? I just want to get the image to display on the screen through code. In the future, it will be when the user selects a button.

User avatar
joan
Posts: 12738
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Trouble installing Pillow / PIL

Mon Jul 14, 2014 9:51 am

The PIL Image show function used to use a program called xv to display the image on *nix systems.

xv has been effectively deprecated for some time.

That might be why you get no display.

tm48
Posts: 19
Joined: Mon May 26, 2014 12:07 pm

Re: Trouble installing Pillow / PIL

Mon Jul 14, 2014 10:38 am

joan wrote:The PIL Image show function used to use a program called xv to display the image on *nix systems.

xv has been effectively deprecated for some time.

That might be why you get no display.
Wow. Thank you for informing me! Do you know of any alternatives that I could use to display an image?

User avatar
joan
Posts: 12738
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Trouble installing Pillow / PIL

Mon Jul 14, 2014 10:58 am

tm48 wrote:
joan wrote:The PIL Image show function used to use a program called xv to display the image on *nix systems.

xv has been effectively deprecated for some time.

That might be why you get no display.
Wow. Thank you for informing me! Do you know of any alternatives that I could use to display an image?
Not my field I'm afraid. I know very little about graphics.

However I just tried the following which appeared to work.

Code: Select all

sudo apt-get install xli

cd /usr/local/bin

sudo ln -s /usr/bin/xli xv
That points the xv command to xli. It worked for me with Python on my laptop.

Code: Select all

Python 2.7.8 (default, Jul  4 2014, 13:08:34) 
[GCC 4.9.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL.Image as Image
>>> a=Image.open("mdb.jpg")
>>> a.show()


User avatar
paddyg
Posts: 1919
Joined: Sat Jan 28, 2012 11:57 am

Re: Trouble installing Pillow / PIL

Sat Aug 02, 2014 8:35 am

For most major unix distributions Pillow has now replaced (the deprecated) PIL. However, for some unknown reason, raspbian continues to hide it away in jessie. NB raspbian maintainers, please move it over SOON!
This is the quickest way to get Pillow/PIL but not feasible from an installation script

Code: Select all

you need to add an additional line to /etc/apt/sources.list:
deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi

(i.e. the same as the existing line but with jessie for wheezy) then run:

sudo apt-get update
sudo apt-get install python-pil
   or
sudo apt-get install python3-pil
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

DirkS
Posts: 7415
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Trouble installing Pillow / PIL

Sat Aug 02, 2014 9:27 am

However, for some unknown reason, raspbian continues to hide it away in jessie
Reason seems clear to me: it's not in Debian wheezy either.

Return to “Beginners”

Who is online

Users browsing this forum: Bing [Bot], boyoh, Partyseed and 52 guests