安装

警告

警告

Pillow 和 PIL 不能共存于同一环境. 在安装 Pillow 之前, 请卸载 PIL.

警告

Pillow > = 1.0 不再支持 “import Image”. 请使用 “from PIL import Image” 来代替.

警告

Pillow > = 2.1.0不再支持 “import _imaging”. 请使用 “from PIL.Image import core as _imaging” 来代替.

注释

注解

Pillow 支持以下 Python 版本

Python

3.8

3.7

3.6

3.5

3.4

3.3

3.2

2.7

2.6

2.5

2.4

Pillow >= 7

Pillow 6.2.1

Pillow 6.0 - 6.2.0

Pillow 5.2 - 5.4

Pillow 5.0 - 5.1

Pillow 4

Pillow 2 - 3

Pillow < 2

基本安装

注解

下面的说明将与最常见的图像格式支持安装Pillow. 请参阅 外部库 支持的外部库的完整列表.

使用 pip 安装 Pillow

python -m pip install pip
python -m pip install Pillow

Windows 安装

我们提供的编译支持Python的车轮, 鸡蛋和可执行安装32位和64位版本的矩阵为Windows Pillow 二进制文件. 这些二进制文件都可选库包括除raqm和libimagequant:

python -m pip install pip
python -m pip install Pillow

MacOS 安装

我们适用于MacOS每个受支持版本的Python在车轮格式提供的二进制文件. 这些措施包括, 除了libimagequant所有可选库的支持. Raqm支持需要libraqm, FriBiDi的, 和的HarfBuzz单独安装:

python -m pip install pip
python -m pip install Pillow

Linux 安装

我们为每个支持Python版本的manylinux轮格式的二进制文件提供的Linux. 这些措施包括, 除了libimagequant所有可选库的支持. Raqm支持需要libraqm, FriBiDi的, 和的HarfBuzz单独安装:

python -m pip install pip
python -m pip install Pillow

大多数主要的Linux发行版, 包括Fedora的, 是Debian/Ubuntu的ArchLinux还包括Pillow在先前包含PIL例如包 python-imaging.

FreeBSD 安装

Pillow在FreeBSD上可以通过官方Ports或Packages系统上安装:

Ports:

cd /usr/ports/graphics/py-pillow && make install clean

Packages:

pkg install py36-pillow

注解

Pillow FreeBSD port 和包均通过 ports 团队所有支持的FreeBSD版本进行测试.

编译源

下载并解压 compressed archive from PyPI.

外部库

注解

不需要安装所有支持的外部库 使用Pillow的基本特性. Zliblibjpeg 在默认情况下需要.

注解

还有 Dockerfiles 在我们的 Docker images repo 安装依赖于某些操作系统.

许多 Pillow 的功能需要外部库:

  • libjpeg 提供JPEG功能.

    • Pillow已经过测试的libjpeg版本 6B, 8, 9-9c 和的 libjpeg 涡轮增压 版本 8.

    • 用Pillow3.0.0开始, libjpeg的默认需要, 但可以用 --disable-jpeg 标志禁止.

  • zlib 提供访问压缩的PNG

    • 用Pillow3.0.0开始, zlib的默认需要, 但可以用 --disable-zlib 标志禁止.

  • libtiff 提供压缩的TIFF功能

    • Pillow 已经利用libtiff版本测试的 3.x4.0

  • libfreetype 提供的类型相关的服务

  • littlecms 提供色彩管理

    • Pillow版本2.2.1及以下使用liblcms1, Pillow2.3.0及以上使用liblcms2. 有 1.19 测试的和 2.7-2.9.

  • libwebp 提供的WebP格式.

    • Pillow已经过测试与版本 0.1.3, 不读透明WebP档案. 版本 0.3.0 及以上版本支持的透明度.

  • tcl/tk 提供Tkinter的位图和照片图像的支持.

  • openjpeg 提供JPEG 2000的功能.

    • Pillow 已经与openjpeg 2.0.0 , 2.1.02.3.1 测试.

    • Pillow不 支持早期 1.5 系列所附带的Debian杰西.

  • libimagequant 提供了改进的颜色量化

    • Pillow 已经与 libimagequant 测试 2.6-2.12.6

    • Libimagequant许可GPLv3的, 这比Pillow许可证更为严格, 因此与libimagequant支持, 使我们不会被分发的二进制文件.

  • libraqm 提供复杂的文本布局支持.

    • libraqm提供双向文本支持(使用FriBiDi的), 整形(使用的HarfBuzz), 以及适当的脚本分项. 其结果是, Raqm可以支持Unicode的覆盖了大部分的书写系统.

    • libraqm取决于以下库:FreeType的, 的HarfBuzz, FriBiDi的, 请务必在系统中安装libraqm如果不作为包之前安装它们.

    • 不支持将文本方向或字体特征而不libraqm.

    • libraqm是动态加载在Pillow5.0.0及以上, 所以支持可当安装所有的库.

    • Windows的支持:Raqm不包括在预置的车轮

一旦你已经安装的先决条件, 运行:

python -m pip install pip
python -m pip install Pillow

如果先决条件都安装在标准库的位置为您的机器(例如 /usr的/usr/local), 应不需要任何附加配置. 如果它们安装在一个非标准位置, 你可能需要配置setuptools的通过编辑使用这些地点 setup.pysetup.cfg, 或者在命令行中加入环境变量:

CFLAGS="-I/usr/pkg/include" python -m pip install pillow

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.

构建选项

  • Environment variable: MAX_CONCURRENCY=n. Pillow can use multiprocessing to build the extension. Setting MAX_CONCURRENCY sets the number of CPUs to use, or can disable parallel building by using a setting of 1. By default, it uses 4 CPUs, or if 4 are not available, as many as are present.

  • Build flags: --disable-zlib, --disable-jpeg, --disable-tiff, --disable-freetype, --disable-lcms, --disable-webp, --disable-webpmux, --disable-jpeg2000, --disable-imagequant. Disable building the corresponding feature even if the development libraries are present on the building machine.

  • Build flags: --enable-zlib, --enable-jpeg, --enable-tiff, --enable-freetype, --enable-lcms, --enable-webp, --enable-webpmux, --enable-jpeg2000, --enable-imagequant. Require that the corresponding feature is built. The build will raise an exception if the libraries are not found. Webpmux (WebP metadata) relies on WebP support. Tcl and Tk also must be used together.

  • Build flag: --disable-platform-guessing. Skips all of the platform dependent guessing of include and library directories for automated build systems that configure the proper paths in the environment variables (e.g. Buildroot).

  • Build flag: --debug. Adds a debugging flag to the include and library search process to dump all paths searched for and found to stdout.

用法示例:

MAX_CONCURRENCY=1 python setup.py build_ext --enable-[feature] install

or using pip:

python -m pip install pillow --global-option="build_ext" --global-option="--enable-[feature]"

在MacOS构建

The Xcode command line tools are required to compile portions of Pillow. The tools are installed by running xcode-select --install from the command line. The command line tools are required even if you have the full Xcode package installed. It may be necessary to run sudo 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 libtiff libjpeg webp little-cms2

要在Mac OS使用自制安装libraqm安装它的依赖:

brew install freetype harfbuzz fribidi

Then see depends/install_raqm_cmake.sh to install libraqm.

现在安装 Pillow

python -m pip install pip
python -m pip install Pillow

或从所述未压缩源目录内:

python setup.py install

在Windows构建

We don’t recommend trying to build on Windows. It is a maze of twisty passages, mostly dead ends. There are build scripts and notes for the Windows build in the winbuild directory.

在FreeBSD构建

注解

只有FreeBSD的10和11测试

请确保你已经安装了Python的开发库:

sudo pkg install python2

或为Python 3:

sudo pkg install python3

先决条件是安装在 FreeBSD的10 或 11 与:

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

Then see depends/install_raqm_cmake.sh to install libraqm.

在Linux上构建

如果您没有从源代码构建Python, 请确保您已安装Python的开发库.

在Debian或者ubuntu:

sudo apt-get install python-dev python-setuptools

或为Python 3:

sudo apt-get install python3-dev python3-setuptools

在Fedora, 该命令是:

sudo dnf install python-devel redhat-rpm-config

或为Python 3:

sudo dnf install python3-devel redhat-rpm-config

注解

redhat-rpm-config 需要在Fedora 23, 但不是早期版本.

前提条件是安装在的与 Ubuntu 16.04 LTS:

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

然后看 depends/install_raqm.sh 安装libraqm.

先决条件安装在最近的 RedHat Centos 的或的 Fedora:

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

请注意, 包管理器可能是百胜集团或地下城与勇士, 取决于具体的分配.

又见 Dockerfiles IN的测试基础设施回购(https://github.com/python-pillow/docker-images)为已知的工作对于其他测试发行版的安装过程.

在Android上构建

基本的Android的支持已经增加了对Termux环境中编译. 该依赖关系可以通过安装:

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

这一问题已经在Chrome操作系统的Termux应用程序中测试, 在x86.

平台支持

对于枕头当前平台的支持. 二进制分发了自愿的基础上每个版本做出了贡献, 但源应编译和运行到处平台支持上市. 在一般情况下, 我们的目标是支持Linux, MacOS和Windows的所有当前版本.

持续集成的目标

这些平台是建立和每一个变化测试.

操作系统

测试的Python版本

经测试架构

Alpine

3.7

x86-64

Arch

3.7

x86-64

Amazon Linux 1

3.6

x86-64

Amazon Linux 2

3.6

x86-64

CentOS 6

3.6

x86-64

CentOS 7

3.6

x86-64

CentOS 8

3.6

x86-64

Debian 9 Stretch

3.5

x86

Debian 10 Buster

3.7

x86

Fedora 30

3.7

x86-64

Fedora 31

3.7

x86-64

macOS 10.13 High Sierra

3.5, 3.6, 3.7, 3.8

x86-64

macOS 10.15 Catalina

PyPy3

x86-64

Ubuntu Linux 16.04 LTS

3.5, 3.6, 3.7, 3.8, PyPy3

x86-64

Windows Server 2012 R2

3.5, 3.8

x86, x86-64

PyPy3, 3.7/MinGW

x86

Windows Server 2019

3.5, 3.6, 3.7, 3.8

x86, x86-64

PyPy3

x86

其他平台

这些平台已报告在工作中提到的版本.

注解

请投稿 Pillow 测试你的平台上, 然后更新此文件并发送pull请求.

操作系统

测试的Python版本

最新的测试 Pillow 版本

经测试的处理器

macOS 10.14 Mojave

2.7, 3.5, 3.6, 3.7

6.0.0

x86-64

3.4

5.4.1

macOS 10.13 High Sierra

2.7, 3.4, 3.5, 3.6

4.2.1

x86-64

macOS 10.12 Sierra

2.7, 3.4, 3.5, 3.6

4.1.1

x86-64

Mac OS X 10.11 El Capitan

2.7, 3.4, 3.5, 3.6, 3.7

5.4.1

x86-64

3.3

4.1.0

Mac OS X 10.9 Mavericks

2.7, 3.2, 3.3, 3.4

3.0.0

x86-64

Mac OS X 10.8 Mountain Lion

2.6, 2.7, 3.2, 3.3

x86-64

Redhat Linux 6

2.6

x86

CentOS 6.3

2.7, 3.3

x86

Fedora 23

2.7, 3.4

3.1.0

x86-64

Ubuntu Linux 12.04 LTS

2.6, 3.2, 3.3, 3.4, 3.5 PyPy5.3.1, PyPy3 v2.4.0

3.4.1

x86,x86-64

2.7

4.3.0

x86-64

2.7, 3.2

3.4.1

ppc

Ubuntu Linux 10.04 LTS

2.6

2.3.0

x86,x86-64

Debian 8.2 Jessie

2.7, 3.4

3.1.0

x86-64

Raspbian Jessie

2.7, 3.4

3.1.0

arm

Raspbian Stretch

2.7, 3.5

4.0.0

arm

Gentoo Linux

2.7, 3.2

2.1.0

x86-64

FreeBSD 11.1

2.7, 3.4, 3.5, 3.6

4.3.0

x86-64

FreeBSD 10.3

2.7, 3.4, 3.5

4.2.0

x86-64

FreeBSD 10.2

2.7, 3.4

3.1.0

x86-64

Windows 8.1 Pro

2.6, 2.7, 3.2, 3.3, 3.4

2.4.0

x86,x86-64

Windows 8 Pro

2.6, 2.7, 3.2, 3.3, 3.4a3

2.2.0

x86,x86-64

Windows 7 Pro

2.7, 3.2, 3.3

3.4.1

x86-64

在Windows Server 2008 R2企业版

3.3

x86-64

老版本

您可以从 PyPI上发行历史 和直接访问URL https://pypi.org/project/Pillow/1.0/下载旧版.