Manual Installation of Python Pillow Library on Mac OS X

May 8, 2020

When you want to install a python library the preferred and recommended method is by using the pip utility.
However there could be several instances when you may want to just use the library without having to perform an installation procedure.

Here we explain how to do a manual installation of the Pillow library on Mac OS X.


Download Pillow Package

First, go to the https://pypi.org/project/Pillow/#files url and locate the file that correspond to Mac OS X, and to your Python version.

At the time of this writing the latest version of the file is Pillow-7.1.2-cp35-cp35m-macosx_10_10_intel.whl, which requires Python greater or equal than 3.5.


If you have an earlier version of Python, you would need to search on the Release history page 
https://pypi.org/project/Pillow/#history for a version of the Pillow library that corresponds to your Python version.

For instance, if you have Python 2.7, you would find that you can use the file 
Pillow-6.2.2-cp27-cp27m-macosx_10_6_intel.whl located on this url https://pypi.org/project/Pillow/6.2.2/#files

Click on the file name to download it. On a Mac, the downloaded files are placed by default on your Downloads folder.


So, open a terminal window, and navigate to that folder with the cd command.


cd ~/Downloads

You can check the file has been downloaded.


ls -l Pillow*.*

You will see an output similar to this one.

-rw-r--r--@ 1 user  staff  2227883 May  8 12:00 Pillow-7.1.2-cp35-cp35m-macosx_10_10_intel.whl

The file you have downloaded is a Wheel file, which is a format used to package python libraries.
This format is a zipped file so we can extract its contents as with any other regular zipped file.


Unzip Pillow Package File

Lets unzip it to a new folder named "PythonPillow" on our home folder.


unzip Pillow-7.1.2-cp35-cp35m-macosx_10_10_intel.whl -d ~/PythonPillow

Check the content of the new folder.


ls -l ~/PythonPillow

You will see the following folder structure.


~/PythonPillow/
   ├─ PIL/
   └─ Pillow-7.1.2.dist-info/

Example Usage

Now we can use the Pillow library on our Python scripts.

In order to do that we need to include the folder containing the PIL library on our script. We will use the sys.path.append method to add the path of the library as shown on the example below.

resize-example.py


import sys

sys.path.append('/Users/USERNAME/PythonPillow')

from PIL import Image

img = Image.open("image.png")

size = (800, 600)

resized = img.resize(size, Image.BICUBIC)
resized.save("image-resized.png")
As we copied the library files on a folder inside our home folder, the path looks like '/Users/USERNAME/PythonPillow' where USERNAME would be our user name.