Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Supporting Python 3

This is a free book about how to make your code support Python 3.

It costs nothing, and you can both publish it and contribute to it!

Reading this book

Supporting Python 3 is available for free on . You can also download a PDF version from for any price you like, and you can buy a paper version from for $4.45, which is the printing cost of the book, and hence as close to free as you can possibly come.

As of today, the name of the book in all these places are "Porting to Python 3", which is the old name of the book before I made it into a community effort. This will change sometime during 2015, and the above links will also change as a result.

Contributing to this book

To contribute to this book, fork it on GitHub.

If you are making any changes or additions that fall under copyright law, you must first sign the Contributor License Agreement.

Follow the instructions in INSTALL.rst on how to install it, and make the changes you like, and create a pull request.

It's probably a good idea to talk to Lennart Regebro before making major changes or additions.


This book is (c) Lennart Regebro 2011-2015, and is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.


This means you can publish this book or parts of it, but not in such a way that you make money from it. Should you want to use this book in a commercial setting, please contact Lennart Regebro,

The book in it's current form uses Flux Bold, which is a commercial font. If you want to publish this book in any form, you need either to replace this font, or buy a license for the usage that you intend.

Generating the PDFs

Making a PDF is not just a matter of doing make pdf. Doing so will indeed create a PDF, but you need to create four PDF's when releasing the book.

You need:

* A print PDF, 6" x 9", black only.
* A screen PDF, 8.27" x 11", with syntax highlighting.
* A tablet PDF, 7" x 9", with syntax highlighting.
* A phone PDF, 4.8" x 7.2", with syntax highlighting.

You do this by changing the For the print PDF, the pygments_style should be "none" otherwise it should be "sphinx".

To select the paper size, change the used variable in print_latex_elements between print_form, screen_form, tablets_form or phone_form.

You don't need to do anything more for the Print PDF, it's done, but the other PDF's should have the front and back covers merged. This can be done with tools like pdfunite:

$ pdfunite covers/PhoneFront.pdf build/latex/SupportingPython3.pdf \
    covers/PhoneBack.pdf SupportingPython3-phone-1.0-dev.pdf

An additional hitch is that each release of Sphinx or texlive will have changes that break the PDF generation, so it's highly unlikely that this book will generate cleanly on your computer. It works on Ubuntu 14.04LTS, but not on Ubuntu 16.04, for example.

You have to install at least the following packages to build the book:

``texlive texlive-xetex texlive-latex-extra lmodern fonts-texgyre
  fonts-linuxlibertine python-sphinx poppler-utils``

EPUB Generation

It is also possible to make an EPUB format of this book with the command make epub - note that at the current time this will lack the front and back covers.

The resulting eBook, in EPUB format, will be placed in the file build/epub/SupportingPython3.epub _or it's windows equivalent.

HTML Generation

It is also possible to make both standalone HTML and HTML directory, (directories with index.html starting points), formats of this book with the commands make html and make dirhtml - note that at the current time these will lack the front and back covers.

The resulting books will be placed in the directories build/html and build/dirhtml respectively.