44

I have an ec2 instance and had Pillow 2.0 installed in my virtualenv initially. Somehow when I tried to upgrade it to Pillow 2.5, it failed with the following message. The error is the same even after I removed Pillow completely prior to reinstall. (So now I don't have Pillow in my virtualenv at all)

$ pip install Pillow
....
....
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ -DHAVE_LIBTIFF -I/usr/include/freetype2 -I/home/andycheng/realprice/env/build/pillow/libImaging -I/home/andycheng/realprice/env/include -I/usr/include/tcl8.5 -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu -c libImaging/RawDecode.c -o build/temp.linux-x86_64-2.7/libImaging/RawDecode.o

gcc: error: unrecognized option ‘-Qunused-arguments’

gcc: error: unrecognized option ‘-Qunused-arguments’

....
....
gcc: error: build/temp.linux-x86_64-2.7/libImaging/XbmEncode.o: No such file or directory

gcc: error: build/temp.linux-x86_64-2.7/libImaging/ZipDecode.o: No such file or directory

gcc: error: build/temp.linux-x86_64-2.7/libImaging/ZipEncode.o: No such file or directory

gcc: error: build/temp.linux-x86_64-2.7/libImaging/TiffDecode.o: No such file or directory

gcc: error: build/temp.linux-x86_64-2.7/libImaging/Incremental.o: No such file or directory

gcc: error: build/temp.linux-x86_64-2.7/libImaging/Jpeg2KDecode.o: No such file or directory

gcc: error: build/temp.linux-x86_64-2.7/libImaging/Jpeg2KEncode.o: No such file or directory

gcc: error: unrecognized option ‘-Qunused-arguments’

gcc: error: unrecognized option ‘-Qunused-arguments’

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /home/andycheng/realprice/env/bin/python -c "import setuptools, tokenize;__file__='/home/andycheng/realprice/env/build/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-U8jA_X-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/andycheng/realprice/env/include/site/python2.7 failed with error code 1 in /home/andycheng/realprice/env/build/Pillow

I don't know if this is related but there are a lot of gcc: error: build/temp.linux-x86_64-2.7/_imaging.o: No such file or directory errors in the log. And there are a lot of gcc: error: unrecognized option ‘-Qunused-arguments’ too.

I am able to install Pillow 2.5 with my root access though, but then the it will not be installed in my virtualenv.

sudo pip install Pillow  # this works but wrong directory
pip install -I Pillow==2.0  # gives the same error and would not install

Versions

PIP: 1.5.4

Linux: Ubuntu 12.04.4 LTS (all package upgraded)

Thank you

2
  • 1
    do you have python-dev installed(command: sudo apt-get install python-dev) ?
    – ruddra
    Commented Jul 9, 2014 at 16:32
  • yes, I have python-dev installed
    – Andy
    Commented Jul 9, 2014 at 23:33

9 Answers 9

93

My case was slightly different as my ubuntu 15.04 was missing also libjpeg, so the installation failed each time. Apparently sometimes pillow can not find required library and the easiest way to fix it is to install the dev version and link it to the user libs. Edit: also works in ubuntu 16.04

sudo apt-get install python-dev
sudo apt-get install libjpeg8-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib

pip install pillow

Partial solution found here

5
  • 4
    I installed libjpeg-dev, which pulled libjpeg62-turbo-dev on my raspberry pi (Raspbian Jessie). This works with Pillow 3.1.0.
    – beruic
    Commented Feb 2, 2016 at 17:40
  • 2
    If you are using python3, then be sure to sudo apt-get install python3-dev (remember the 3) Commented Jan 16, 2017 at 4:15
  • <sudo apt-get install libjpeg8-dev> did solve the pip install issue for me as well on raspberry pi (Jessie Version 8) Commented Jul 20, 2018 at 14:15
  • Awesome. Works like a charm in Raspbian Commented Dec 5, 2018 at 16:55
  • for Debian 10, py3.9 this helped me: sudo apt-get install python3-dev libjpeg-dev
    – mirek
    Commented Dec 1, 2020 at 13:27
40

Note for myself and any others, getting this to compile on Elementary OS Luna (Ubuntu 12.04) requires installation of the python headers you need for your virtualenv python version per the comments on the OP. I am using the default python version and testing 3.4 (via deadsnakes ppa) so for me this was:

sudo apt-get install python-dev
sudo apt-get install python3.4-dev

BUT! I was still getting the same error! I checked my .bashrc per the OPs answer, I didn't have any matching exports. Then it hit me, I'd been troubleshooting for a while and from an answer somewhere else I had tried setting those and hadn't restarted bash.

So don't forget to restart (or re-source I suppose) bash to make sure your exports match .bashrc!

edit: This is a bit long for a comment but not really an answer. Will modify if necessary.

4
  • This is fine as an answer! sudo apt-get install python-dev fixed the problem on my Ubuntu 12.04 box. No other steps needed. (It's a local VirtualBox though, not really an Amazon EC2 image.)
    – Peterino
    Commented Nov 20, 2014 at 13:31
  • 4
    In many of these cases, installing the python-dev package for the specific version of Python you are using in your virtenv is the key... For me, v3.3 for this project, worked: sudo apt-get install python3.3-dev ... +1 Commented Dec 17, 2014 at 19:57
  • 1
    sudo apt-get install python3.5-dev worked on ubuntu16.10 (gnome). Commented Apr 26, 2016 at 21:08
  • 1
    sudo apt-get install python3.4-dev works on ubuntu 14.04
    – gorantq
    Commented Sep 23, 2016 at 5:55
26

I had the same headache too...

The solution was found after reading docs, that says:

Starting from version 3.0.0 Pillow needs libjpeg...

So try the previous one:

pip install pillow==2.9.0

(It works for python 2.6 and above)

Good Luck!

1
  • Does not seem to work with Python 3.4, Linux 3.13.0-147
    – Nemo
    Commented Oct 29, 2018 at 12:06
11

The new version 3.0 doesn't work, we need to install the 2.9.0 version which works with Django. Do this while inside the virtual environment:

pip install Pillow==2.9.0

This should work also in Ubuntu, I use Elementary OS.

2
  • I tried installing libjpeg8-dev per Mr.Coffee's answer; didn't work. Tried installing python3.4-dev; didn't work. Using version 2.9 worked. Commented Jan 22, 2016 at 14:26
  • I was too facing the same problem.....With your solution i was able to install pillow....Thanks mate. Commented May 18, 2016 at 18:47
8

Finally I have found the answer to this headache!

It turns out I have two flag settings in my .bashrc:

export CFLAGS=-Qunused-arguments                                    
export CPPFLAGS=-Qunused-arguments

The .bashrc was copied from my Macbook Pro and these two flags were required as a work around for XCODE. It seems that they will break in Linux.

After removing these two flags, pip install Pillow works as expected.

Thanks everyone for the help.

1
  • Yes! Thank you! This was such an obscure error for me. I moved from a Mac to Ubuntu, and some of the packages I was installing (namely virtualenvburrito) were largely geared towards mac users, so I believe they inserted these flags into my environment somehow. To fix it, I added the following two lines to my .bashrc: export CFLAGS='' export CPPFLAGS=''
    – Spike
    Commented Jan 29, 2018 at 1:15
4

Ubuntu 16.04 virtualenv

pip install pillow==2.9.0
2

You might need to install the python development headers.

sudo apt-get install build-dep python-imaging
0

On Fedora, installing rpm-build solved it for me. Make sure you have python-devel and libjpeg-devel installed too.

0

On my CentOS machine I had to:

yum install python-devel

Not the answer you're looking for? Browse other questions tagged or ask your own question.