Как установить PIL/pillow в Python 3.4.3?
При установке через pip install в командной строке появляется ошибка. В папке Scripts pip и EI установлены, и эта папка добавлена в PATH. Работаю через Python IDLE
Отслеживать
Villager12345
задан 8 ноя 2020 в 13:57
Villager12345 Villager12345
9 2 2 бронзовых знака
pip — это программа, которую нужно запускать в командной строке системы, а не в командной строке питона
8 ноя 2020 в 14:01
«pip не является внутренней или внешней командой, исполняемой программой или пакетным файлом»
8 ноя 2020 в 14:14
Значит вы забыли перейти в папку с этими программами или забыли добавить папку с программами в переменную окружения PATH
8 ноя 2020 в 14:19
1 ответ 1
Сортировка: Сброс на вариант по умолчанию
Попробуйте запустить ту же самую команду, но только в командной строке, например вот так: pip install Pillow==2.2.1 .
Или же если Вы работаете в jupyter notebook, то добавьте в начале команды ! и просто вставьте в запускаемую строчку, вот так:
In [1]: !pip install Pillow==2.2.1
Кстати если сомневаетесь правильно ли написали команду для установки по протоколу pip , то её всегда можно проверить на сайте PyPi как я это сделал сейчас.
Основные возможности библиотеки Python Imaging Library / Pillow / PIL
PIL, известная как библиотека Python Imaging Library, может быть использована для работы с изображениями достаточно легким способом. У PIL не было никаких изменений и развития с 2009. Поэтому, добрые пользователи этого сайта предложили взглянуть на Pillow еще раз. Эта статья поможет вам узнать как пользоваться Pillow.
Что такое Pillow?
Pillow это форк PIL (Python Image Library), которая появилась благодаря поддержке Алекса Кларка и других участников. Основана на коде PIL, а затем преобразилась в улучшенную, современную версию. Предоставляет поддержку при открытии, управлении и сохранении многих форматов изображения. Многое работает так же, как и в оригинальной PIL.
Загрузка и установка Pillow
Перед началом использования Pillow, нужно загрузить и установить ее. Pillow доступна для Windows, Mac OS X и Linux. Самая “свежая” версия — это версия “8.1.0”, она поддерживается на python 3.6 и выше. Для установки Pillow на компьютеры Windows используйте conda или pip :
conda install -c anaconda pillow pip install Pillow
Для установки Pillow на компьютерах Linux просто используйте:
$ sudo pip install Pillow
А установки Pillow на MacOS X нужно для начала установить XCode, а затем Homebrew. После того как Homebrew установлен, используйте:
$ brew install libtiff libjpeg webp littlecms $ sudo pip install Pillow
Убедитесь, что Pillow установлена
Убедитесь, что Pillow установлена, откройте терминал и наберите следующее в текущей строке:
$ python Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from PIL import Image
Если система показывает снова >>> , значит модули Pillow правильно установлены.
Форматы файлов
Перед началом использования модуля Pillow, давайте укажем некоторые поддерживаемые типы файлов: BMP, EPS, GIF, IM, JPEG, MSP, PCX PNG, PPM, TIFF, WebP, ICO, PSD, PDF . Некоторые типы файлов возможны только для чтения, в то время как другие доступны только для написания. Чтобы увидеть полный список поддерживаемых типов файла и больше информации о них, ознакомьтесь с руководством к Pillow.
Как использовать Pillow для работы с изображениями
Поскольку мы собираемся работать с изображениями, для начала, скачаем одно. Если у вас уже есть изображение, которое хотите использовать, пропустите этот шаг, описанный ниже.
В нашем примере будем использовать стандартное тестовое изображение под названием «Lenna» или «Lena». Это изображение используется во многих экспериментах по обработке изображений. Просто зайдите сюда и загрузите изображение. Если вы нажмете на изображение, оно сохранится как изображение с количеством пикселей 512×512.
Использование Pillow
Давайте посмотрим на возможные варианты использования этой библиотеки. Основные функции находятся в модуле Image . Вы можете создавать экземпляры этого класса несколькими способами. Путем загрузки изображений из файлов, обработки других изображений, либо создания изображений с нуля. Импортируйте модули Pillow, которые вы хотите использовать.
Installing PIL/Pillow/cImage for Python on Windows and Mac
Python is a widely-used programming language used in many of the computer science classes here at St. Olaf.
What is PIL/Pillow?
PIL (Python Imaging Library) adds many image processing features to Python. Pillow is a fork of PIL that adds some user-friendly features.
What is cImage?
cImage.py is a Python module used for image processing.
Installing Python, PIL/Pillow, and cImage.py
Windows
- Install Python 2.7.8 (64-bit — this is important)
- https://www.python.org/ftp/python/2.7.8/python-2.7.8.amd64.msi
- https://www.python.org/ftp/python/3.4.1/python-3.4.1.amd64.msi
- https://pypi.python.org/packages/2.7/P/Pillow/Pillow-2.5.3.win-amd64-py2.7.exe#md5=33c3a581ff1538b4f79b4651084090c8
- https://pypi.python.org/packages/3.4/P/Pillow/Pillow-2.5.3.win-amd64-py3.4.exe#md5=6ee659d7b945e826a07c53c15578424f (direct link)
- https://pypi.python.org/pypi/Pillow/ (all other versions)
- Download cImage.py from Github
- Navigate to https://github.com/bnmnetp/cImage
- Click cImage.py, and click the button labeled Raw to see the contents of the file.
- Click File >Save Page As (Chrome & Firefox) or File >Save As (Safari) to save the file on your computer.
- Copy “cImage.py” from where you saved it to C:\Python27\Lib\site-packages and C:\Python34\Lib\site-packages\
Mac
- Install Python 3.4.1 (Python 2.7 is already installed by default)
- https://www.python.org/ftp/python/3.4.1/python-3.4.1-macosx10.6.dmg
- xcode-select –install (You will be prompted to install the Xcode Command Line Tools)
- sudo easy_install pip
- sudo pip install pillow
- pip3.4 install pillow
- Download cimage.py
- Navigate to https://github.com/bnmnetp/cImage
- Click cImage.py, and click the button labeled Raw to see the contents of the file.
- Click File->Save Page As (Chrome & Firefox) or File->Save As (Safari) to save the file on your computer.
- Copy “cImage.py” from where you saved it to Macintosh HD/Library/Python/2.7/site-packages/
- Copy “cImage.py” from where you saved it to Macintosh HD/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/
St. Olaf College
1520 St. Olaf Avenue
Northfield, MN 55057Installation#
Warning Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.
Warning Pillow >= 1.0 no longer supports import Image . Please use from PIL import Image instead.
Warning Pillow >= 2.1.0 no longer supports import _imaging . Please use from PIL.Image import core as _imaging instead.
Python Support#
Pillow supports these Python versions.
Newer versions #
Python 3.12 3.11 3.10 3.9 3.8 3.7 3.6 3.5 Pillow >= 10.1 Yes Yes Yes Yes Yes Pillow 10.0 Yes Yes Yes Yes Pillow 9.3 — 9.5 Yes Yes Yes Yes Yes Pillow 9.0 — 9.2 Yes Yes Yes Yes Pillow 8.3.2 — 8.4 Yes Yes Yes Yes Yes Pillow 8.0 — 8.3.1 Yes Yes Yes Yes Pillow 7.0 — 7.2 Yes Yes Yes Yes Older versions #
Python 3.8 3.7 3.6 3.5 3.4 3.3 3.2 2.7 2.6 2.5 2.4 Pillow 6.2.1 — 6.2.2 Yes Yes Yes Yes Yes Pillow 6.0 — 6.2.0 Yes Yes Yes Yes Pillow 5.2 — 5.4 Yes Yes Yes Yes Yes Pillow 5.0 — 5.1 Yes Yes Yes Yes Pillow 4 Yes Yes Yes Yes Yes Pillow 2 — 3 Yes Yes Yes Yes Yes Yes Pillow < 2 Yes Yes Yes Yes Basic Installation#
Note The following instructions will install Pillow with support for most common image formats. See External Libraries for a full list of external libraries supported.
Install Pillow with pip:
python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow
We provide binaries for Linux for each of the supported Python versions in the manylinux wheel format. These include support for all optional libraries except libimagequant. Raqm support requires FriBiDi to be installed separately:
python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow
Most major Linux distributions, including Fedora, Ubuntu and ArchLinux also include Pillow in packages that previously contained PIL e.g. python-imaging . Debian splits it into two packages, python3-pil and python3-pil.imagetk .
We provide binaries for macOS for each of the supported Python versions in the wheel format. These include support for all optional libraries except libimagequant. Raqm support requires FriBiDi to be installed separately:
python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow
While we provide binaries for both x86-64 and arm64, we do not provide universal2 binaries. However, it is simple to combine our current binaries to create one:
python3 -m pip download --only-binary=:all: --platform macosx_10_10_x86_64 Pillow python3 -m pip download --only-binary=:all: --platform macosx_11_0_arm64 Pillow python3 -m pip install delocate
Then, with the names of the downloaded wheels, use Python to combine them:
from delocate.fuse import fuse_wheels fuse_wheels('Pillow-9.4.0-2-cp39-cp39-macosx_10_10_x86_64.whl', 'Pillow-9.4.0-cp39-cp39-macosx_11_0_arm64.whl', 'Pillow-9.4.0-cp39-cp39-macosx_11_0_universal2.whl')
Warning Pillow > 9.5.0 no longer includes 32-bit wheels.
We provide Pillow binaries for Windows compiled for the matrix of supported Pythons in 64-bit versions in the wheel format. These binaries include support for all optional libraries except libimagequant and libxcb. Raqm support requires FriBiDi to be installed separately:
python3 -m pip install --upgrade pip python3 -m pip install --upgrade Pillow
To install Pillow in MSYS2, see Building on Windows using MSYS2/MinGW.
Pillow can be installed on FreeBSD via the official Ports or Packages systems: Ports:cd /usr/ports/graphics/py-pillow && make install clean
Packages:
pkg install py38-pillow
Note The Pillow FreeBSD port and packages are tested by the ports team with all supported FreeBSD versions.
Building From Source#
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.
- libjpeg provides JPEG functionality.
- Pillow has been tested with libjpeg versions 6b, 8, 9-9d and libjpeg-turbo version 8.
- Starting with Pillow 3.0.0, libjpeg is required by default, but may be disabled with the —disable-jpeg flag.
- Starting with Pillow 3.0.0, zlib is required by default, but may be disabled with the —disable-zlib flag.
- Pillow has been tested with libtiff versions 3.x and 4.0-4.6.0
- Pillow version 2.2.1 and below uses liblcms1, Pillow 2.3.0 and above uses liblcms2. Tested with 1.19 and 2.7-2.15.
- Pillow has been tested with version 0.1.3, which does not read transparent WebP files. Versions 0.3.0 and above support transparency.
- Pillow has been tested with openjpeg 2.0.0, 2.1.0, 2.3.1, 2.4.0 and 2.5.0.
- Pillow does not support the earlier 1.5 series which ships with Debian Jessie.
- Pillow has been tested with libimagequant 2.6-4.2.2
- Libimagequant is licensed GPLv3, which is more restrictive than the Pillow license, therefore we will not be distributing binaries with libimagequant support enabled.
- libraqm provides bidirectional text support (using FriBiDi), shaping (using HarfBuzz), and proper script itemization. As a result, Raqm can support most writing systems covered by Unicode.
- libraqm depends on the following libraries: FreeType, HarfBuzz, FriBiDi, make sure that you install them before installing libraqm if not available as package in your system.
- Setting text direction or font features is not supported without libraqm.
- Pillow wheels since version 8.2.0 include a modified version of libraqm that loads libfribidi at runtime if it is installed. On Windows this requires compiling FriBiDi and installing fribidi.dll into a directory listed in the Dynamic-link library search order (Microsoft Learn) ( fribidi-0.dll or libfribidi-0.dll are also detected). See Build Options to see how to build this version.
- Previous versions of Pillow (5.0.0 to 8.1.2) linked libraqm dynamically at runtime.
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
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 see depends/install_raqm.sh .
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 Dockerfile s in the Test Infrastructure repo (https://github.com/python-pillow/docker-images) for a known working install process for other tested distros.
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 libjpeg libtiff little-cms2 openjpeg webp
To install libraqm on macOS use Homebrew to install its dependencies:
brew install freetype harfbuzz fribidi
Then see depends/install_raqm_cmake.sh to install libraqm.
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 the Installing instructions will not be necessary afterwards.
Windows using MSYS2/MinGW
To build Pillow using MSYS2, make sure you run the MSYS2 MinGW 32-bit or MSYS2 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
https://www.msys2.org/docs/python/ states that setuptools >= 60 does not work with MSYS2. To workaround this, before installing Pillow you must run:
export SETUPTOOLS_USE_DISTUTILS=stdlib
Only FreeBSD 10 and 11 tested
Make sure you have Python’s development libraries installed:
sudo pkg install python3
Prerequisites are installed on FreeBSD 10 or 11 with:
sudo pkg install jpeg-turbo tiff webp lcms2 freetype2 openjpeg harfbuzz fribidi libxcb
Then see depends/install_raqm_cmake.sh to install libraqm.
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 or setup.cfg , 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/Pillow or 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#
- 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.
- Config settings: -C zlib=disable , -C jpeg=disable , -C tiff=disable , -C freetype=disable , -C raqm=disable , -C lcms=disable , -C webp=disable , -C webpmux=disable , -C jpeg2000=disable , -C imagequant=disable , -C xcb=disable . Disable building the corresponding feature even if the development libraries are present on the building machine.
- Config settings: -C zlib=enable , -C jpeg=enable , -C tiff=enable , -C freetype=enable , -C raqm=enable , -C lcms=enable , -C webp=enable , -C webpmux=enable , -C jpeg2000=enable , -C imagequant=enable , -C xcb=enable . 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.
- Config settings: -C raqm=vendor , -C fribidi=vendor . These flags are used to compile a modified version of libraqm and a shim that dynamically loads libfribidi at runtime. These are used to compile the standard Pillow wheels. Compiling libraqm requires a C99-compliant compiler.
- Build flag: -C platform-guessing=disable . 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: -C debug=true . Adds a debugging flag to the include and library search process to dump all paths searched for and found to stdout.
python3 -m pip install --upgrade Pillow -C [feature]=enable
Platform Support#
Current platform support for Pillow. Binary distributions are contributed for each release on a volunteer basis, but the source should compile and run everywhere platform support is listed. In general, we aim to support all current versions of Linux, macOS, and Windows.
Continuous Integration Targets#
These platforms are built and tested for every change.
