[Python Note] install the source code of the image processing library PIL

Source: Internet
Author: User
Tags image processing library

[Python Note] install the source code of the image processing library PIL

Some time ago, the project needed to watermark some images and use the Python PIL library. This article takes Imaging-1.1.7 as an example to record the source code compilation/installation steps of the PIL library.

PIL is the full name of Python Image Library. It supports processing in multiple Image formats and can represent powerful Image processing capabilities for our applications, such as cropping, rotating, and watermarking.

Download the source code of v1.1.7 from the official website and decompress it. Then, run cd to the decompressed directory. read README. If you want to process jpeg images in an application, you must install the jpeg library in advance. Otherwise, an error will be reported during use.

1. Compile and install the jpeg Library

1.1 compile source code

Download the jpeg source code of the stable version from the jpeg library official website (the latest stable version is v9a), decompress the gz package of the source code, cd to the decompressed directory, vi open the Makefile file, and modify it in two places:

1) set the prefix variable to the installation path of the jpeg library.

2) append the-fPIC parameter in CFLAGS settings (for details about the role of PIC, refer to man gcc or here)

Note: A _ Imaging must be compiled when Imaging is installed later. so library file, so the-fPIC parameter must be set here, otherwise the following error will be reported during Imaging compilation (if you want to verify it, you can try -_-):

/usr/bin/ld: /home/slvher/python-2.7.5/3rd-lib-src/jpeg-6b/lib/libjpeg.a(jcparam.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC/home/slvher/python-2.7.5/3rd-lib-src/jpeg-6b/lib/libjpeg.a: could not read symbols: Bad valuecollect2: ld returned 1 exit statuserror: command 'gcc' failed with exit status 11.2 install-lib

After compiling the jpeg source code with the-fPIC parameter, run the following command:

make install

Make install-lib and above commands install the compiled jpeg Library to the path specified by prefix (in fact, from the source code directory cp file to the prefix directory)

2. Install the Imaging Library

Cd to Imaging-1.1.7, vi open setup. py, modify the file:

1) Comment out pai_root = None

2) Add cmd_root = libinclude ("/home/slvher/python-2.7.5/3rd-lib-src/jpeg-6b"), save and exit and execute the following command:

Python setup. py build_ext-I

Normally, the Imaging library is compiled successfully.

Run the following command to install the PIL Library to the site-packages directory of python:

python setup.py install

Then, the application can use the GIL library normally.

Related Article

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.