Pillow can run across platforms, such as Windows, Linux, macOS, etc. The latest version is Pillow 8.4.0, which supports Python 3.6 and above (recommended). This article will tell you what is pillow, and how to install the python pillow module on Windows, Linux & macOS.
1. What Is Pillow?
- PIL (Python Imaging Library) is the third-party image processing library of Python. It is highly praised because of its rich functions and simple API.
- Since 2011, due to the slow update of the PIL library and only supporting Python version 2.7, it obviously can not meet the use requirements of Python version 3. So a group of Python community volunteers developed an image processing library supporting Python 3 based on the PIL library, which is Pillow.
- Pillow is not only a “replica” of the PIL library but also adds many new features to the PIL library. Till now, the pillow has become a more active image processing library than PIL.
- Now Pillow is the basic image processing library in Python that is used for basic images processing, such as cropping, resizing, and color processing.
2. Pillow vs OpenCV vs Scikit-image.
- In addition to the PIL and Pillow libraries, python also provides some other image processing libraries such as OpenCV, Scikit-image.
- OpenCV is actually a C++ image processing library, but it provides a Python interface.
- Scikit-image is an image processing software package based on Scipy that processes images in the form of arrays.
- Compared with Pillow, OpenCV and Scikit-image have richer functions, so they are more complex to use. They are mainly used in machine vision, image analysis, and other fields, such as the well-known “face recognition” application.
3. Pillow Package Features.
- Pillow supports a wide range of image formats, such as “JPEG”, “PNG”, “BMP”, “GIF”, “PPM”, “TIFF” and more. It also supports conversion between image formats.
- Pillow provides rich image processing capabilities that can be summarized in two areas, they are image archive and image processing.
- Image archiving includes creating thumbnails, generating preview images, image batch processing, etc.
- Image processing includes adjusting image size, cutting images, pixel processing, adding filters, image color processing, and so on.
- The Pillow library can be used with the Python GUI (graphical user interface) tool Tkinter.
- The Pillow library can also perform more complex image processing operations, such as adding watermarks to images and compositing animated gifs.
4. How To Install Python Pillow Library.
- Pillow installation is very simple and convenient, there are three ways to install the Pillow, they are 1) Install using PIP package manager, 2) Install using Anaconda, 3) Install using the binary package files.
- Note that the PIL library and Pillow library are not allowed to coexist in the same environment. If you have installed the PIL library before, please uninstall it and then install Pillow.
4.1 Install Pillow Using Anaconda.
- Anaconda is an open-source distribution of Python, it is a popular scientific computing platform, supporting Windows, Linux, and macOS systems ( you can refer to How To Install Anaconda On Linux, Windows, macOS Correctly). So we recommend you use it.
- Open the Anaconda navigator window, then click the Environments menu item on the Anaconda navigator left panel.
- Then select the virtual environment item that you need on the window’s middle side virtual environments list.
- On the window right side, select All from the drop-down list, then input the keyword pillow in the search box.
- If your anaconda has downloaded the pillow module, it will show the pillow module below the search box.
- You can check the checkbox before the pillow module and then click the Apply button to install it.
- You can read the article How To Install/Uninstall Python Packages In Anaconda Virtual Environment Successfully to learn more.
4.2 Install Pillow Using PIP Package Manager.
- Installing Pillow through the PPIP is the simplest, lightweight way to install it, and it works on any platform.
- Open a terminal and run the command pip install pillow in it to install the python pillow module.
- Then run the command pip show pillow to verify that pillow has been installed successfully.
$ pip show pillow Name: Pillow Version: 8.1.0 Summary: Python Imaging Library (Fork) Home-page: https://python-pillow.org Author: Alex Clark (PIL Fork Author) Author-email: [email protected] License: HPND Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages Requires: Required-by: vaex-viz, streamlit, matplotlib, ipyvolume
4.3 Install Pillow Using The Binary Package Files.
- Go to the pillow package files download page to download the pillow binary files that match your OS and version.
- Then open a terminal and run the below commands to install the pillow module with the above binary files.
- For Windows, you can run the command py -m pip install ./downloads/Pillow-8.4.0.tar.gz.
- For Linux & macOS, you can run the comand python3 -m pip install ./downloads/Pillow-8.4.0.tar.gz.
- You can read the Install a particular python module through the local source archive file to learn more.
5. How To Use Pillow In Python Source Code.
- Open a terminal and run the command python in it to open the python interpreter console.
- Then input the python source code from PIL import Image in the python console and press the enter key.
- If there is no error prompts, then it means the python pillow module has been installed successfully.
$ python Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> from PIL import Image # Import the Image class, which is an important class in pillow for Image processing.