10

I know that this question looks like a duplicate but I've followed many online instructions on how to properly install PIL and none have worked.

I've tried everything in: Python Image Library fails with message "decoder JPEG not available" - PIL with no success.

When I run sudo pip install pil, worst of all, there is a misleading error. Jpeg, Freetyle, etc support is all listed as available. But when running some python code using PIL, the notorious IOError of "decoder jpeg not available' comes up.

Even after symlinking into /usr/lib for the .so libjpeg files, nothing has worked.

Any ideas? Thank you.

Community
  • 1
  • 1
Lucas Ou-Yang
  • 5,505
  • 13
  • 43
  • 62

1 Answers1

19

You can try this:

1. clear PIL packages

rm -rf /usr/lib/python2.7/site-packages/PIL
rm -rf /usr/lib/python2.7/site-packages/PIL.pth

2. install required packages

ubuntu:
apt-get install libjpeg-dev libfreetype6-dev zlib1g-dev libpng12-dev

centos:
yum install zlib zlib-devel
yum install libjpeg libjpeg-devel
yum install freetype freetype-devel

3.download Image and install

wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
tar xzvf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
# if the sys is x64, you must also do this: edit the setup.py file and set:
# centOS:
TCL_ROOT = '/usr/lib64'
JPEG_ROOT = '/usr/lib64'
ZLIB_ROOT = '/usr/lib64'
TIFF_ROOT = '/usr/lib64'
FREETYPE_ROOT = '/usr/lib64'
LCMS_ROOT = '/usr/lib64'
# Ubuntu:
TCL_ROOT = '/usr/lib/x86_64-linux-gnu'
JPEG_ROOT = '/usr/lib/x86_64-linux-gnu'
ZLIB_ROOT = '/usr/lib/x86_64-linux-gnu'
TIFF_ROOT = '/usr/lib/x86_64-linux-gnu'
FREETYPE_ROOT = '/usr/lib/x86_64-linux-gnu'
LCMS_ROOT = '/usr/lib/x86_64-linux-gnu'
#then install it use:
python2.7 setup.py install

4. check if it works

# before this command you should run `mv PIL PIL2`

python2.7 selftest.py

If the result is:

--- PIL CORE support ok
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
*** LITTLECMS support not installed
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.

Congratulation!!

SHernandez
  • 1,060
  • 1
  • 14
  • 21
Wee
  • 234
  • 3
  • 9
  • I'm try solution but ` ImproperlyConfigured: Error importing module ` "No module named PIL" – Goran Dec 05 '13 at 00:07
  • 1
    use `import Image` replace `from PIL import Image` – Wee Dec 10 '13 at 07:28
  • having same error .. then i followed yours . test is passed but throwing below error `.. Exception Location: build/bdist.linux-x86_64/egg/PIL/Image.py in _getdecoder, line 415` – Raja Simon Oct 29 '14 at 11:38
  • Failure in example: len(im.tostring()) from line #76 of selftest.testimage Exception raised: Traceback (most recent call last): File "./doctest.py", line 499, in _run_examples_inner exec compile(source, "", "single") in globs File "", line 1, in File "/home/ubuntu/.local/lib/python2.7/site-packages/PIL/Image.py", line 697, in tostring "Please call tobytes() instead.") NotImplementedError: tostring() has been removed. Please call tobytes() instead. – Jithin U. Ahmed Mar 07 '17 at 09:41
  • 1 items had failures: 1 of 57 in selftest.testimage ***Test Failed*** 1 failures. *** 1 tests of 57 failed. – Jithin U. Ahmed Mar 07 '17 at 09:41