Python's PIL installation can be a headache, if you want to use a graphical program in python to store an image from a binary stream (e.g., using Scrapy to crawl the web to store an image), you'll need to use PIL.
This library, however, is notoriously difficult to install.
The way it works is that if you use Scrapy's ImagePipeline it will use PIL by default, and if you don't have the pattern decoder installed correctly you'll get the following error.
IOError: decoder jpeg not available
I've searched for a lot of methods on the Internet and still can't do it, and I don't know what is going on, I thought there was a problem with the installation of PIL library, but even after installing PIL correctly, the above error still occurs. The reason lies in the decoder decoder problem.
Then I found a package called Imaging-1.1.7, and installed it randomly, and it worked, so I ignored it. Technical debt is always payable, but I didn't expect to encounter the same problem on Ubuntu again so soon before the project release, and I'm not sure if I'll be able to pay it back.
Used the package directly, but it turned out to be...
The answer, of course, is painfully obvious, or IOError ~
Well, let bygones be bygones, and after a lot of fussing and fiddling there's finally a silver lining, so look out for the following table of information.
-------------------------------------------------------------------- PIL 1.1.7 SETUP SUMMARY -------------------------------------------------------------------- version 1.1.7 platform linux2 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] -------------------------------------------------------------------- *** TKINTER support not available *** JPEG support not available *** ZLIB (PNG/ZIP) support not available *** FREETYPE2 support not available *** LITTLECMS support not available --------------------------------------------------------------------
Notes.This table is shown after using the python build command in the Imaging installation directory.
If you look at it in detail you'll see that, yes! None of the image decoders are supported. The problem is not with the PIL, but with the decoders. The decoders must have been installed before I was able to get a good install on OSX.
So that other people don't fall into this trap again, here's how to install it.
Mac OSX
brew update
brew install libjpeg libpng
These two are enough.
Ubuntu 14.0.4
sudo apt-get install libjpeg-dev libpng12-dev libfreetype6-dev libtiff-dev
Linux is a bit worse, you have to install several packages.
If that's not enough, it's better to use the python package Pillow instead of downloading Imaging by hand, just use the following commands
pip install -I --no-cache-dir -v Pillow
There will be a lot of information after this command is executed, don't worry about it, just find the following.
-------------------------------------------------------------------- PIL SETUP SUMMARY -------------------------------------------------------------------- version Pillow 3.2.0 platform linux2 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available *** OPENJPEG (JPEG2000) support not available --- ZLIB (PNG/ZIP) support available *** LIBTIFF support not available --- FREETYPE2 support available *** LITTLECMS2 support not available *** WEBP support not available *** WEBPMUX support not available -------------------------------------------------------------------- To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the script. To check the build, run the script.
There you go! And here's a tip: look at the top line.To check the build, run the script. this one It's a good thing. At least we'll know if it worked.
Good luck with the installation!