[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:When Imaging is installed later, you need to compile a _ Imaging. 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 1
1.2 install-lib
After compiling the jpeg source code with the-fPIC parameter, run the following command:
make installmake install-lib
The above command will install the compiled jpeg Library to the path specified by prefix (in fact, it is 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.
[References]
1. PIL Official Website
2. PIL source code README document