SoFunction
Updated on 2024-12-13

python install pil library method and code

Installation of PIL

Install directly via apt under Debian/Ubuntu Linux:

$ sudo apt-get install python-imaging

Mac and other versions of Linux can be installed directly using easy_install or pip, you need to put the compilation environment in place before installation:

$ sudo easy_install PIL

If the installation fails, follow the prompts to install the missing packages (e.g. openjpeg) first.

For Windows platform just go to the official PIL website and download the exe installer.

Manipulating Images

Take a look at the most common image scaling operations, which require only three or four lines of code:

import Image

 

# Open a jpg image file, note that the path should be changed to your own:.

im = ('/Users/michael/')

# Obtain image size.

w, h = 

# Scaled to 50%.

((w//2, h//2))

# Save the scaled image in jpeg format.

('/Users/michael/', 'jpeg')

Other features such as slicing, rotating, filters, output text, color palettes, and more are readily available.


I. Install pip

The python libraries are generally installed with pip.

pip is already available for p3.6. If not, it can be used in the following /~gohlke/pythonlibs/#pillow

Download pip-9.0.1-py2. and run it to install it.

Remember to add the scripts for the python installer to the environment variable, as follows

II. Download PIL

The official version of PIL does not support py3, but there is an unofficial alternative, pillow, at /~gohlke/pythonlibs/#pillow.

Note the choice of version: my python is Python 3.6.1 and my system is 64-bit

Select Pillow-4.1.1-cp36-cp36m-win_amd64.whl

cp36 stands for cpython3.6, usually cp and python versions are the same.

III. Installation of PIL

Menu type cm, open command prompt, run as administrator, type pip install Pillow-4.1.1-cp36-cp36m-win_amd64.whl, but there is an error, suggesting that the corresponding file is not found in C:\Windows\System32.

So I put Pillow-4.1.1-cp36-cp36m-win_amd64.whl into C:\Windows\System32

Bingo!