Home » Python » Image library for Python 3

Image library for Python 3

Posted by: admin November 1, 2017 Leave a comment


What is python-3 using instead of PIL for manipulating Images?


The “friendly PIL fork” Pillow works on Python 2 and 3. Check out the Github project for support matrix and so on.


Christoph Gohlke managed to build PIL (for Windows only) for python versions up to 3.3: http://www.lfd.uci.edu/~gohlke/pythonlibs/

I tried his version of PIL with Python 3.2, and image open/create/pixel manipulation/save all work.


Qt works very well with graphics. In my opinion it is more versatile than PIL.

You get all the features you want for graphics manipulation, but there’s also vector graphics and even support for real printers. And all of that in one uniform API, QPainter.

To use Qt you need a Python binding for it: PySide or PyQt4.
They both support Python 3.

Here is a simple example that loads a JPG image, draws an antialiased circle of radius 10 at coordinates (20, 20) with the color of the pixel that was at those coordinates and saves the modified image as a PNG file:

from PySide.QtCore import *
from PySide.QtGui import *

app = QCoreApplication([])

img = QImage('input.jpg')

g = QPainter(img)
g.setBrush(QColor(img.pixel(20, 20)))
g.drawEllipse(QPoint(20, 20), 10, 10)


But please note that this solution is quite ‘heavyweight’, because Qt is a large framework for making GUI applications.


As of March 30, 2012, I have tried and failed to get the sloonz fork on GitHub to open images. I got it to compile ok, but it didn’t actually work. I also tried building gohlke’s library, and it compiled also but failed to open any images. Someone mentioned PythonMagick above, but it only compiles on Windows. See PythonMagick on the wxPython wiki.

PIL was last updated in 2009, and while it’s website says they are working on a Python 3 port, it’s been 3 years, and the mailing list has gone cold.

To solve my Python 3 image manipulation problem, I am using subprocess.call() to execute ImageMagick shell commands. This method works.

See the subprocess module documentation.


You can use my package mahotas on Python 3. It is numpy-based rather than PIL based.


You want the Pillow library, here is how to install it on Python 3:

pip3 install Pillow

If that does not work for you (it should), try normal pip:

pip install Pillow


The original PIL author planned to port to Python 3. Check this message in the mailing list: http://mail.python.org/pipermail/image-sig/2009-March/005498.html

However, for the last 3 years, there has been no further work by the original author.

As to what you can use NOW, I’ve no idea. I’m sticking with Python 2.6 until 3.0 has more widespread support from third-party libraries.

Maybe you could do the image work in some other language.