Building from source (original) (raw)

External libraries

Note

You do not need to install all supported external libraries to use Pillow’s basic features. Zlib and libjpeg are required by default.

Note

There are Dockerfiles in our Docker images repo to install the dependencies for some operating systems.

Many of Pillow’s features require external libraries:

Linux

If you didn’t build Python from source, make sure you have Python’s development libraries installed.

In Debian or Ubuntu:

sudo apt-get install python3-dev python3-setuptools

In Fedora, the command is:

sudo dnf install python3-devel redhat-rpm-config

In Alpine, the command is:

sudo apk add python3-dev py3-setuptools

Note

redhat-rpm-config is required on Fedora 23, but not earlier versions.

Prerequisites for Ubuntu 16.04 LTS - 22.04 LTS are installed with:

sudo apt-get install libtiff5-dev libjpeg8-dev libopenjp2-7-dev zlib1g-dev
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk
libharfbuzz-dev libfribidi-dev libxcb1-dev

To install libraqm, sudo apt-get install meson and then seedepends/install_raqm.sh.

Build prerequisites for libavif on Ubuntu are installed with:

sudo apt-get install cmake ninja-build nasm

Then see depends/install_libavif.sh to build and install libavif.

Prerequisites are installed on recent Red Hat, CentOS or Fedora with:

sudo dnf install libtiff-devel libjpeg-devel openjpeg2-devel zlib-devel
freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel
harfbuzz-devel fribidi-devel libraqm-devel libimagequant-devel libxcb-devel

Note that the package manager may be yum or DNF, depending on the exact distribution.

Prerequisites are installed for Alpine with:

sudo apk add tiff-dev jpeg-dev openjpeg-dev zlib-dev freetype-dev lcms2-dev
libwebp-dev tcl-dev tk-dev harfbuzz-dev fribidi-dev libimagequant-dev
libxcb-dev libpng-dev

See also the Dockerfiles in the Test Infrastructure repo (https://github.com/python-pillow/docker-images) for a known working install process for other tested distros.

macOS

The Xcode command line tools are required to compile portions of Pillow. The tools are installed by running xcode-select --installfrom the command line. The command line tools are required even if you have the full Xcode package installed. It may be necessary to runsudo xcodebuild -license to accept the license prior to using the tools.

The easiest way to install external libraries is via Homebrew. After you install Homebrew, run:

brew install libavif libjpeg libraqm libtiff little-cms2 openjpeg webp

If you would like to use libavif with more codecs than just aom, then instead of installing libavif through Homebrew directly, you can use Homebrew to install libavif’s build dependencies:

brew install aom dav1d rav1e svt-av1

Then see depends/install_libavif.sh to install libavif.

Windows

We recommend you use prebuilt wheels from PyPI. If you wish to compile Pillow manually, you can use the build scripts in the winbuild directory used for CI testing and development. These scripts require Visual Studio 2017 or newer and NASM.

The scripts also install Pillow from the local copy of the source code, so theInstalling instructions will not be necessary afterwards.

Windows using MSYS2/MinGW

To build Pillow using MSYS2, make sure you run the MSYS2 MinGW 32-bit orMSYS2 MinGW 64-bit console, not MSYS2 directly.

The following instructions target the 64-bit build, for 32-bit replace all occurrences of mingw-w64-x86_64- with mingw-w64-i686-.

Make sure you have Python and GCC installed:

pacman -S
mingw-w64-x86_64-gcc
mingw-w64-x86_64-python3
mingw-w64-x86_64-python3-pip
mingw-w64-x86_64-python3-setuptools

Prerequisites are installed on MSYS2 MinGW 64-bit with:

pacman -S
mingw-w64-x86_64-libjpeg-turbo
mingw-w64-x86_64-zlib
mingw-w64-x86_64-libtiff
mingw-w64-x86_64-freetype
mingw-w64-x86_64-lcms2
mingw-w64-x86_64-libwebp
mingw-w64-x86_64-openjpeg2
mingw-w64-x86_64-libimagequant
mingw-w64-x86_64-libraqm
mingw-w64-x86_64-libavif

FreeBSD

Note

Only FreeBSD 10 and 11 tested

Make sure you have Python’s development libraries installed:

Prerequisites are installed on FreeBSD 10 or 11 with:

sudo pkg install jpeg-turbo tiff webp lcms2 freetype2 openjpeg harfbuzz fribidi libxcb libavif

Then see depends/install_raqm_cmake.sh to install libraqm.

Android

Basic Android support has been added for compilation within the Termux environment. The dependencies can be installed by:

pkg install -y python ndk-sysroot clang make
libjpeg-turbo

This has been tested within the Termux app on ChromeOS, on x86.

Installing

Once you have installed the prerequisites, to install Pillow from the source code on PyPI, run:

python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow --no-binary :all:

If the prerequisites are installed in the standard library locations for your machine (e.g. /usr or /usr/local), no additional configuration should be required. If they are installed in a non-standard location, you may need to configure setuptools to use those locations by editing setup.py orpyproject.toml, or by adding environment variables on the command line:

CFLAGS="-I/usr/pkg/include" python3 -m pip install --upgrade Pillow --no-binary :all:

If Pillow has been previously built without the required prerequisites, it may be necessary to manually clear the pip cache or build without cache using the --no-cache-dir option to force a build with newly installed external libraries.

If you would like to install from a local copy of the source code instead, you can clone from GitHub with git clone https://github.com/python-pillow/Pillowor download and extract the compressed archive from PyPI.

After navigating to the Pillow directory, run:

python3 -m pip install --upgrade pip python3 -m pip install .

Build options

Sample usage:

python3 -m pip install --upgrade Pillow -C [feature]=enable

Old versions

You can download old distributions from the release history at PyPI and by direct URL access eg. https://pypi.org/project/pillow/1.0/.