A simple tutorial on PIL installation in python

Source: Internet
Author: User
This article mainly shares a simple tutorial on PIL installation in python. if you are interested, you can refer to this article to explain how to install PIL in python, for more information, see

Installing python PIL is a headache. if you want to use a graph program in python, you may just save an image from a binary stream (for example, using Scrapy to crawl a graph ), PIL will be used.
This library, and this library is famous for being difficult to install.

It shows that if you use Scrapy's ImagePipeline, PIL will be used by default. if you do not correctly install the image decoder, the following errors will occur:

IOError: decoder jpeg not available
I have found many methods on the Internet, but I still don't know whether it is. I thought it was a problem with the installation of the PIL library, but even if PIL is correctly installed, the above errors will still occur. the reason is the decoder problem.

Later, I found a package named Imaging-1.1.7 and installed it without any errors. technical debt is always to be paid back, but I did not expect it to be so fast. the release of near-term projects encountered the same problem on Ubuntu,
Use this package directly, but the result is...

The answer is of course painful, or IOError ~

Well, let's let it go when it's painful. after some tossing, we finally find a glimmer of light. please pay attention to the following table information:

--------------------------------------------------------------------PIL 1.1.7 SETUP SUMMARY--------------------------------------------------------------------version    1.1.7platform   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--------------------------------------------------------------------

Note:This table is displayed after the python setup. py build command is used in the Imaging installation directory.

If you see it in detail, you will find it, right! All image decoding is not supported. The problem is not on PIL, but on decoder. I have installed decoder before on OSX.

To prevent other friends from falling into this trap, I specially sorted out the installation method:

Mac OSX
Brew update
Brew install libjpeg libpng
It is enough to install the two.

Ubuntu 14.0.4
Sudo apt-get install libjpeg-dev libpng12-dev libfreetype6-dev libtiff-dev
Linux is a little miserable. you need to install several more packages.

This is not enough. it is best to directly use the python package Pillow to replace the manual download of the Imaging package. use the following command directly.

Pip install-I -- no-cache-dir-v Pillow
After the command is executed, there will be a lot of information. you just need to find the following information:

--------------------------------------------------------------------PIL SETUP SUMMARY--------------------------------------------------------------------version   Pillow 3.2.0platform   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 requiredlibrary, and set the corresponding ROOT variable in thesetup.py script.To check the build, run the selftest.py script.

This goes down! There is also a small note: Please pay attention to the above line,To check the build, run the selftest. py script.ThisSelftest. pyIt's a good stuff. at least you can know if it's successful.

We wish you a successful installation!

The above is the details of the PIL installation simple tutorial in python. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.