Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOError: decoder jpeg not available when using Pillow

Tags:

python

pillow

Before someone says "sudo apt-get install libjpeg-dev" or something along those lines, I do not have sudo access. I am on a slice of a server that does NOT allow me to have sudo access. So I've gotta do this entire thing in my local directory. That's the only way I can do it.

I need a python script to resize an image. It works perfectly fine for png files, but it falls apart on jpeg files with the error listed in the title.

Here are the steps I've taken so far:

  1. Downloaded libjpeg-dev and installed it to $HOME/jpegtest, so inside the jpegtest/ folder is lib/, include/, and so on
  2. I downloaded Pillow manually and extracted it out to $HOME/Pillow
  3. I edited the setup.py fild so the JPEG_ROOT to a libinclude(<absolute path to jpegtest>)
  4. I built and compiled Pillow, where it installed to $HOME//.pythonbrew/pythons/Python-2.7.5/lib/python2.7/site-packages/Pillow-2.4.0-py2.7-linux-x86_64.egg The important part of the output is as follows:

    *** TKINTER support not available
    --- JPEG support available
    *** OPENJPEG (JPEG2000) support not available
    --- ZLIB (PNG/ZIP) support available
    *** LIBTIFF support not available
    *** FREETYPE2 support not available
    *** LITTLECMS2 support not available
    *** WEBP support not available
    *** WEBPMUX support not available
    

So I would assume that this means JPEG support will function, but when I run my program it says:

IOError: decoder jpeg not available

While typing this I also noticed the question at Pillow recognizes JPEG encoder on install, but not use, which sounded very close to mine, so I tried the solution there:

ln -s /media/sdl1/home/midnight/jpegtest/lib/libjpeg.so /media/sdl1/home/midnight/.pythonbrew/pythons/Python-2.7.5/lib

But I still have the same error.

I've been working on this problem for about two days now, and I'm not entirely sure what to do. If anyone could offer some assistance, that would be very helpful.

like image 674
Thomas Riley Avatar asked Jun 06 '14 20:06

Thomas Riley


1 Answers

Instead of just downloading the libraries you need, try creating an entire Python environment in locally in your home folder:

$ wget http://www.python.org/ftp/python/[desired version of Python].tgz
$ tar xzf Python[version].tgz
$ cd python-[version]
$ ./configure
$ make altinstall prefix=~ exec-prefix=~

Update your PATH variable so that your local Python is executed first:

$ PATH = /home/user/[pathtopython]:$PATH

Obtain pip, from which other packages can be installed:

$ curl https://bootstrap.pypa.io/get-pip.py > get-pip.py
$ ./get-pip.py
$ pip install pillow

URLs may vary. You might still have to modify setup.py - I haven't used this technique with C-like libraries so I'm not sure.

like image 140
A--- Avatar answered Oct 05 '22 23:10

A---