16

Currently I'm installing PIL into my virtual env as follows:

pip install -E . -r ./releases/%s/requirements.txt

where requirements.txt contains:

pil

I can upload png images but not jpeg images currently. From reading on the web it seems i may need libjpeg decoder? Am i installing pil incorrectly? What is the proper way to install pil for django in a virtual env with libjpeg?

John Mee
  • 50,179
  • 34
  • 152
  • 186
prostock
  • 9,327
  • 19
  • 70
  • 118
  • 1
    As far as I know, libjpeg needs to be installed in your libraries prior to installing pil. Good question however. If there's a better practice, I'd love to know. – Belmin Fernandez Dec 14 '10 at 02:26
  • What OS are you running? Find libjpeg in your package management system if that applies to you. You'll probably want to uninstall PIL before you try re-installing so it will re-compile. – Kekoa Jan 29 '11 at 02:59

6 Answers6

14

You should install the libraries that others recommended but most importantly you should tell PIL where to find them. Edit the setup.py so that

    JPEG_ROOT = None 

becomes

JPEG_ROOT = libinclude("/usr/lib") 

I found that the easiest way was to download the source with pip but not install:

 pip install --no-install PIL

edit the setup (inside the build directory of the virtual environment) and the install

 pip install PIL

you can find some more information in my blog

You can also try pillow which seems to do great job with little hassle (pip install pillow)

Dimitris
  • 2,501
  • 3
  • 21
  • 28
  • 1
    See also this Ubuntu thread http://ubuntuforums.org/showthread.php?t=1751455&page=2 – Bryce Jan 18 '12 at 22:56
  • 1
    Path in Ubuntu 12.04: /usr/lib/x86_64-linux-gnu – Scoutman Mar 08 '13 at 19:56
  • Ran into the same problem with pillow (2.8.1). I had to do `pip install --no-install pillow`, and then replace the JPEG_ROOT line with `JPEG_ROOT = ("/path/to/libjpeg/lib", "/path/to/libjpeg/include")`. Finally install with `pip install /path/to/virtualenv/build/pillow` ---- Just in case someone (including myself) needs this in the future – Claude Apr 29 '15 at 20:25
10

On Ubuntu precise, PIL doesn't find the jpeg library files, even once they are installed. The easiest way to fix this is to make a symlink after you have installed the jpeg dev package. So, I needed an extra step:

pip uninstall PIL
sudo apt-get install libjpeg8-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
pip install PIL
edward
  • 2,455
  • 23
  • 12
8

For Ubuntu 11.04, what finally worked for me is:

pip uninstall PIL
sudo apt-get install libjpeg8-dev
pip install PIL

The Python Imaging Library (PIL) seems really picky about version and location of the jpeg libraries. And because PIL is written in C and compiled, you need the development versions of the library in addition to the runtime versions.

The situation is so bad the community forked PIL to create a softer version: Pillow: http://pypi.python.org/pypi/Pillow#why-a-fork

Bryce
  • 8,313
  • 6
  • 55
  • 73
6

On OSX, I used the following binary to get libpng and libjpeg simultaneously installed systemwide:

libpng & libjpeg for OSX

Because I already had PIL installed (via pip on a virtualenv), I ran:

pip uninstall PIL
pip install PIL --upgrade

This resolved the decoder JPEG not available error for me.

zeantsoi
  • 25,857
  • 7
  • 69
  • 61
  • many, many thanks! The key bit for me was the binary, because I tried installing libjpeg using `brew`, but that didn't work for me, while this nailed it (OSX 10.8.3). – Morgan Wilde May 15 '13 at 10:19
3

You must install the libraries:

sudo aptitude install libjpeg62 libjpeg62-dev zlib1g-dev
diegueus9
  • 29,351
  • 16
  • 62
  • 74
1

if pip raises an error, try easy_install PIL

dvska
  • 2,399
  • 1
  • 19
  • 14