Trouble installing Pillow / PIL
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?
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?
Re: Trouble installing Pillow / PIL
What was the exact command you used for installation?I tried to do sudo apt-get and it says it is done but then it doesn't work.
How did you try to use it?
Did you get any error messages?
Gr
Dirk.
Re: Trouble installing Pillow / PIL
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:
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.
Code: Select all
sudo apt-get install python-dev python-setuptools
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.
Re: Trouble installing Pillow / PIL
I was trying to do something like:DirkS wrote: How did you try to use it?
Code: Select all
from PIL import image
global ext
ext = ".jpg"
imageFile = "test.jpg"
img = Image.open(imageFile)
Code: Select all
import Image
img = Image.open("test.jpg")
img.save("test.png")
img.show()
Re: Trouble installing Pillow / PIL
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.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:What should I do to fix that? Should I just try downloading it again?Code: Select all
sudo apt-get install python-dev python-setuptools
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'.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.
As said, since you don't know what error message you got I would just start from the beginning again.
HTH
Dirk.
Re: Trouble installing Pillow / PIL
Okay so here is what I got:
I did this: And I got no errors and it said that its already installed. I don't get why it says there is no module.
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
Code: Select all
sudo apt-get install python-setuptools
Re: Trouble installing Pillow / PIL
Aha... it seems you're using python 3. It has its own version of the setuptools so you have to usetm48 wrote:Code: Select all
pi@raspberrypi ~/Pillow-2.3.0 $ sudo python3 setup.py
Code: Select all
sudo apt-get install python-setuptools
Code: Select all
sudo apt-get install python3-setuptools
Dirk.
Re: Trouble installing Pillow / PIL
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
- DougieLawson
- Posts: 42635
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Trouble installing Pillow / PIL
sudo python3 setup.py install
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
Re: Trouble installing Pillow / PIL
Great! That seemed to work. Thank you!
Re: Trouble installing Pillow / PIL
So I must have done something wrong because I used this command:
This is the code that I have so far:
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?
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?DougieLawson wrote:sudo python3 setup.py install
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
Re: Trouble installing Pillow / PIL
It's hard to tell, without seeing the exact error message...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?

Re: Trouble installing Pillow / PIL
It highlights "iml" inAndrewS wrote: It's hard to tell, without seeing the exact error message...
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
Re: Trouble installing Pillow / PIL
That's because in Python3, print is a function rather than a statement, so you'd need to change it totm48 wrote:It highlights "iml" inAndrewS wrote: It's hard to tell, without seeing the exact error message...and a pop up that says invalid syntax comes up.Code: Select all
print iml.format
Code: Select all
print(iml.format)
This suggests that using pip3 is more reliable for installing pillow than setuptools is?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
Re: Trouble installing Pillow / PIL
I was following that but got an error when I was downloading this dependency:AndrewS wrote: This suggests that using pip3 is more reliable for installing pillow than setuptools is?
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 then the final install commands on that page are only for Ubuntu. What should I do?E: Unable to locate package libfreetype6-dev
Re: Trouble installing Pillow / PIL
Remove the backslash from the install command line:
and try again.
Gr.
Dirk.
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
Gr.
Dirk.
Re: Trouble installing Pillow / PIL
Nevermind, I got those to work when I downloaded them individually. Now, my problem is just with these commands:tm48 wrote:I was following that but got an error when I was downloading this dependency:AndrewS wrote: This suggests that using pip3 is more reliable for installing pillow than setuptools is?The error I got isCode: Select all
sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev \ libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev
E: Unable to locate package libfreetype6-dev
I get an error: Invalid operation pip3Install Pillow
For Ubuntu 13.10+: sudo pip3 install Pillow
and for 13.04-: sudo pip-3.2 install Pillow
[/quote]
Re: Trouble installing Pillow / PIL
After doing 'sudo apt-get install python3-pip' on Raspbian, I then have a pip-3.2 command available...tm48 wrote:Now, my problem is just with these commands:I get an error: Invalid operation pip3Install Pillow
For Ubuntu 13.10+: sudo pip3 install Pillow
and for 13.04-: sudo pip-3.2 install Pillow

Re: Trouble installing Pillow / PIL
That worked! Now I have this code in IDLE3 that compiles but doesn't show me the image:AndrewS wrote: After doing 'sudo apt-get install python3-pip' on Raspbian, I then have a pip-3.2 command available...
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)
Re: Trouble installing Pillow / PIL
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.
xv has been effectively deprecated for some time.
That might be why you get no display.
Re: Trouble installing Pillow / PIL
Wow. Thank you for informing me! Do you know of any alternatives that I could use to display an image?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.
Re: Trouble installing Pillow / PIL
Not my field I'm afraid. I know very little about graphics.tm48 wrote:Wow. Thank you for informing me! Do you know of any alternatives that I could use to display an image?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.
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
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()
Re: Trouble installing Pillow / PIL
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
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
Re: Trouble installing Pillow / PIL
Reason seems clear to me: it's not in Debian wheezy either.However, for some unknown reason, raspbian continues to hide it away in jessie