Installing Python Pillow: A Comprehensive Guide
Python's Pillow library, a fork of the Python Imaging Library (PIL), is a powerful tool for processing and manipulating images. It provides a wide range of image processing features, making it an essential library for any Python developer working with images. In this guide, we'll walk you through the process of installing Pillow in a step-by-step manner, ensuring you have the library ready to use in your Python projects.
Prerequisites
Before we begin, ensure you have the following prerequisites installed on your system:
- Python (3.5 or later)
- pip (Python's package installer, comes bundled with Python)
Installing Pillow via pip
The recommended way to install Pillow is using pip, Python's package installer. Here's how you can do it:

-
Open your terminal or command prompt.
Type the following command and press Enter:
pip install pillow
pip will download and install Pillow along with its dependencies. You'll see output similar to this:

Collecting pillow
Downloading Pillow-8.4.0-cp38-cp38-manylinux_2_17_x86_64.whl (32.1 MB)
|████████████████████████████████| 32.1 MB 1.5 MB/s
Installing collected packages: pillow
Successfully installed pillow-8.4.0
Verifying the Installation
To verify that Pillow has been installed correctly, open a Python shell or script and import the library:
from PIL import Image
print(Image.__version__)
The script should print the installed version of Pillow, confirming that the library has been successfully installed.
Troubleshooting Common Issues
While installing Pillow, you might encounter some common issues. Here's how you can troubleshoot them:

| Issue | Solution |
|---|---|
| Error: "No module named 'PIL'" | You might be using an older version of Python. Upgrade to Python 3.5 or later, and try installing Pillow again. |
| Error: "Cannot install Pillow, requires C++ compiler" | Pillow requires a C++ compiler to build from source. If you're using a Linux distribution, install a C++ compiler using your package manager (e.g., `sudo apt-get install build-essential` for Ubuntu). |
Using Pillow in Your Projects
Now that you have Pillow installed, you can start using it in your Python projects. Here's a simple example of opening and displaying an image using Pillow:
from PIL import Image
import sys
try:
img = Image.open('example.jpg')
except FileNotFoundError:
print("File not found")
sys.exit(1)
img.show()
This script opens the 'example.jpg' file and displays it using your system's default image viewer.
Congratulations! You've successfully installed and verified the Pillow library. You're now ready to explore the vast world of image processing with Python. Happy coding!






















