1 Installing Python

Last edited

Python versioning

  • Python has an annual release cycle: feature releases happen every October
  • Each feature release gets a new minor version in Python’s major.minor.micro scheme.
  • Feature versions are maintained for five years, after which they reach end-of-life
  • prereleases fall into three consecutive phases: alphas, betas, and release candidates a1, b3, rc2

python versioning

Python Installers

Python on Linux

Typically installed through the Linux distro (apt, dnf).

TODO: Pyenv etc…

pyenv

pyenv is for building python versions from source.

pyenv install 3.6.8
Downloading Python-3.6.8.tar.xz...

This has not worked for me with a clean output. Althought I think they built. The need to do this is rare anyway, just download compiled interpreters.

hatch

Install hatch with the standalone binary on Linux.

https://github.com/pypa/hatch

hatch python install 3.10
Installed 3.10 @ /home/mat/.local/share/hatch/pythons/3.10

py --list
 3.10 │ /home/mat/.local/share/hatch/pythons/3.10/python/bin/python3.10 

uv has a python installer similar, you can use it as well

Install through their install script.

uv python install 3.12
Installed Python 3.12.11 in 31ms
➜  python git:(main) ✗ py --list
 3.12 │ /home/mat/.local/bin/python3.12                         

Controlling which interpreter runs

Interpreter discovery the process of locating the python interpreter to execute a program:

  • shebang - entry point scripts reference their environment
  • shells - locate the interpreter by searching $PATH, $VIRTUAL_ENV for python, python3, python3.x, additionally using windows registry for windows

Locating Python Interpreters

PATH is less relevant in windows because Python installs can be located via Windows Registry.

When you type python3 at the command line:
the shell searches the directories in the PATH environment variable from left to right and invokes the first executable file named python3

python shadowing

Python Entry Point for Unix

Pithy

py is just an interface to select a python interpreter

Just download the binary. I did this it seems to work well and fast. I think this may be the way to go.

https://github.com/brettcannon/python-launcher.git

The creator is a cpython maintainer, so you can use this if you’d like to select python interpreters, same as on windows with py instead of invoking the interpreter directly.

Its key benefit is a unified, cross-platform way to launch Python, with a well-defined default when no version is specified: the newest interpreter on the system.

Shebangs

If you invoke py with a Python script but don’t specify a version, py inspects the first line of the script for a shebang (a line specifying the interpreter for the script).

#!/usr/bin/env python3
...