Hypermodern Python Tooling
by Claudio Jolowicz
Copyright 2024 Claudio Jolowicz. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (https://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Acquisitions Editor: Brian Guerin
- Development Editor: Sarah Grey
- Production Editor: Gregory Hyman
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Kate Dullea
- April 2024: First Edition
Revision History for the Early Release
- 2022-11-01: First Release
- 2023-01-31: Second Release
See https://oreilly.com/catalog/errata.csp?isbn=9781098139582 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Hypermodern Python Tooling, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the author, and do not represent the publishers views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-098-13958-2
Chapter 1. Installing Python
A Note for Early Release Readers
With Early Release ebooks, you get books in their earliest formthe authors raw and unedited content as they writeso you can take advantage of these technologies long before the official release of these titles.
This will be the first chapter of the final book. Please note that the GitHub repo will be made active later on.
If you have comments about how we might improve the content and/or examples in this book, or if you notice missing material within this chapter, please reach out to the author at .
If youve picked up this book, you likely have Python installed on your machinealready. Most common operating systems ship with a python
or python3
command. This can be the interpreter used by the system itself or a shim thatinstalls Python for you when you invoke it for the first time.
Why dedicate an entire chapter to the topic if its so easy to get Python onto anew machine? The answer is that installing Python for long-term development canbe a complex matter, and there are several reasons for this:
You generally need multiple versions of Python installed side-by-side. (Ifyoure wondering why, well get to that shortly.)
There are a few different ways to install Python across the common platforms,each with unique advantages, tradeoffs, and sometimes pitfalls.
Python is a moving target: You need to keep existing installations up-to-datewith the latest maintenance release, add installations when a new featureversion is published, and remove versions that are no longer supported. Youmay even need to test a prerelease of the next Python.
You may want your code to run on multiple platforms. While Python makes iteasy to write portable programs, setting up a developer environment requiressome familiarity with the idiosyncrasies of each platform.
You may want to run your code with an alternative implementation ofPython.
In this first chapter, Ill show you how to install multiple Python versions onsome of the major operating systems in a sustainable way, and how to keep yourlittle snake farm in good shape.
Tip
If you only develop for a single platform, feel free to skip ahead to yourpreferred platform. Id encourage you to learn about working with Python onother operating systems though. Its funand familiarity with other platformsenables you to provide a better experience to the contributors and users of yoursoftware.
Supporting Multiple Versions of Python
Python programs often target several versions of the language and standardlibrary at once. This may come as a surprise. Why would you run your code withanything but the latest Python? After all, this lets your programs benefit fromnew language features and library improvements immediately.
As it turns out, runtime environments often come with a variety of olderversions of Python. Even if you havetight control over your deployment environments, you may want to get into thehabit of testing against multiple versions. The day the trusty Python in yourproduction environment features in a security advisory better not be the day youstart porting your code to newer releases.
For these reasons, it is common to support both current and past versions ofPython until their official end-of-life date, and to set up installations forthem side-by-side on a developer machine. With new feature versions coming outevery year and support extending over five years, this gives you a testingmatrix of five actively supported versions (see). If that sounds like a lot of work, dontworry: the Python ecosystem comes with tooling that makes this a breeze.
The Python Release Cycle
Python has an annual release cycle: feature releases happen every October. Eachfeature release gets a new minor version in Pythons major.minor.micro
scheme.By contrast, new major versions are rare and reserved for strongly incompatiblechangesat the time of writing this book, a Python 4 is not in sight. Pythonsbackward compatibility policy allows incompatible changes in minor releases whenpreceded by a two-year deprecation period.
Feature versions are maintained for five years, after which they reachend-of-life. Bugfix releases for a feature version occur roughly every othermonth during the first 18 months after its initial release. This is followed bysecurity updates whenever necessary during the remainder of the five-yearsupport period. Each maintenance release bumps the micro version.
Prereleases for upcoming Python feature releases happen throughout the yearbefore their publication. These prereleases fall into three consecutive phases:alphas, betas, and release candidates. You can recognize them by the suffix thatgets appended to the upcoming Python version, indicating the release status andsequence number, such as a1
, b3
, rc2
.
Figure 1-1. Timeline of Python Releases
Locating Python Interpreters
How do you select the correct Python interpreter if you have multiple ones onyour system? Lets look at a concrete example. When you type python
at thecommand line, the shell searches the directories in the PATH
environmentvariable from left to right and invokes the first executable file named