Install Python 3.14 with uv on Linux, macOS and Windows
Pick a Python version for October 2026, install it with uv or your OS, avoid the PEP 668 "externally managed" error, and run your first script.
Python is the second language of most DevOps work, after the shell. Cloud SDKs such as boto3, configuration tools such as Ansible, and many of the command-line tools you run every day are written in it. You reach for Python when a Bash script starts to parse JSON, call HTTP APIs, retry on errors or needs tests: those jobs take a few lines in Python and a lot of care in Bash.
This part gets a current Python onto your machine without breaking the one your operating system depends on. You choose a version, install it with uv or with your package manager, meet the "externally managed environment" error that pip shows on Debian and Ubuntu (and the fix), create the virtual environment the rest of the guide uses, and run your first script.
Prerequisites
- A Linux, macOS or Windows computer with a terminal. This part shows the Windows commands, but later parts use Linux commands and a Bash shell (
&,echo $?,chmod, signals), so on Windows follow the rest of the guide in WSL 2, and install uv and Python inside WSL with the Linux commands. - Basic terminal use:
cd,ls, editing a file. The Linux command line part of the Linux guide covers it. - No Python experience. If you already write Python, skim this part for the version notes and the uv setup, then move on.
Which Python Version to Use in October 2026
Python releases a new minor version every October. Each one gets about two years of bug fixes and then security fixes only, until it reaches end of life five years after its release. This is where every version stands today (from the release cycle data on python.org):
| Version | First released | Latest release | Status | End of life |
|---|---|---|---|---|
| 3.15 | 9 October 2026 | 3.15.1 (21 October 2026) | Bug fixes | October 2031 |
| 3.14 | 7 October 2025 | 3.14.9 (21 October 2026) | Bug fixes | October 2030 |
| 3.13 | 7 October 2024 | 3.13.17 (21 October 2026) | Security fixes only | October 2029 |
| 3.12 | 2 October 2023 | 3.12.15 (30 September 2026) | Security fixes only | October 2028 |
| 3.11 | 24 October 2022 | 3.11.17 (1 October 2026) | Security fixes only | October 2027 |
| 3.10 | 4 October 2021 | none | End of life (1 Oct 2026) | Ended |
This guide uses Python 3.14. It is the newest version that has had a full year of bug fixes, it is the python3 of Ubuntu 26.04 LTS and Fedora 44, and every library the guide uses ships ready-made packages for it. Python 3.15 came out on 9 October 2026 and 3.15.1 followed on 21 October. It is a good choice for new projects once the libraries you depend on support it; Part 10 runs the example project's tests on 3.15 as well. Avoid 3.10 and older for anything new: they no longer get security fixes.
The Python your operating system ships is often older, and it belongs to the operating system:
| System | python3 version (October 2026) |
|---|---|
| Ubuntu 24.04 LTS | 3.12.3 |
| Ubuntu 26.04 LTS | 3.14.4 |
| Debian 12 (bookworm) | 3.11.2 |
| Debian 13 (trixie) | 3.13.5 |
| Fedora 44 | 3.14.8 |
| RHEL 9 and its rebuilds | 3.9 (3.11, 3.12 and 3.14 as extra packages) |
| RHEL 10 and its rebuilds | 3.12 |
| macOS | none of its own (see the macOS tab below) |
| Windows | none |
Tools such as cloud-init, Ubuntu's unattended-upgrades and add-apt-repository, dnf on RHEL, and parts of your desktop run on that system Python. Upgrading or replacing it breaks them, and installing packages into it with sudo pip is the classic way to break a server. So the rule for the whole guide is: leave the system Python alone, and give each project its own Python packages in a virtual environment.
Install uv and Python
uv is a single program, written in Rust by Astral, that installs Python versions, creates virtual environments, installs packages and manages projects. It replaces pyenv, virtualenv, pip, pip-tools and pipx for most people, and it is much faster than those tools. You do not need it to learn Python, but it is the simplest way to get the same Python 3.14 on Linux, macOS and Windows, and Part 6 uses it for packaging.
Piping a script from the internet into sh runs whatever the server sends, so read it first when that matters to you, or install uv from your package manager. Here is a real run of the pinned installer on Linux:
The installer also added ~/.local/bin to your PATH in your shell's startup files, so new terminals find uv without the source line.
Now install Python 3.14. uv downloads a ready-made build of CPython (the standard Python, from the python-build-standalone project) into your home directory. Nothing touches the system Python, and you do not need sudo:
uv python list shows both: the 3.14.9 that uv manages, and the system's own /usr/bin/python3 (3.11.2 on this Debian 12 machine), which stays untouched. uv python install 3.15 would add Python 3.15 next to it in the same way, and uv python upgrade 3.14 moves you to the next 3.14 bug-fix release when it comes out.
The "Externally Managed Environment" Error
If you use the distribution's Python instead, you will meet this sooner or later. Here is a fresh Ubuntu 26.04 LTS server with the python3 and python3-pip packages installed:
This is PEP 668 at work. Debian, Ubuntu, Arch Linux and Alpine put a file called EXTERNALLY-MANAGED next to the system Python's standard library, and pip refuses to install anything into that Python, because the packages you install could replace the ones the package manager installed and break system tools. pip install --user is refused too. Fedora and RHEL do not ship the marker, but the advice is the same there: do not install into the system Python with sudo pip. The error lists the ways out; the right one for your own code is a virtual environment: a directory with its own python and its own packages, built on top of a base Python.
On Debian and Ubuntu, the module that creates virtual environments is packaged separately, so the obvious command fails on a fresh system:
Install the package once (it is python3-venv, which pulls in the right version-specific package), and it works:
Never "fix" the error with pip install --break-system-packages or by deleting the EXTERNALLY-MANAGED file on a server. Part 6 explains virtual environments, pip, uv and the other options in depth.
Create the Project for This Guide
Parts 1 to 9 of this guide work in one directory, ~/pyops, with one virtual environment in it (Part 10 creates a project of its own). Create both with uv:
Activating a virtual environment only changes your shell: it puts .venv/bin first in PATH (so python is the environment's own) and adds (pyops) to the prompt. An environment created by uv contains no pip; you install packages into it with uv pip install or uv add, as Part 6 shows. deactivate undoes it. You can also skip activation and call .venv/bin/python directly, which is what scripts and cron jobs should do.
In every later part, start by going to the project and activating it: cd ~/pyops && source .venv/bin/activate. The commands in the guide then use python, which is the environment's Python 3.14.
The Interactive Shell
Run python with no arguments and you get the REPL (read, evaluate, print loop), where each line runs as soon as you press Enter. It is the fastest way to try something out:
Since Python 3.13 the REPL is much nicer to use: it colours the prompt and tracebacks (3.14 adds syntax highlighting as you type), lets you edit a whole multi-line block with the arrow keys, and understands exit and help without parentheses. Press F1 for help, F2 to browse your history and F3 for paste mode when you paste a block of code. The transcripts in this guide come from the basic REPL (PYTHON_BASIC_REPL=1), which shows the same text without the colours.
Leave the REPL with exit (exit() in the basic REPL) or Ctrl+D (Ctrl+Z then Enter on Windows).
Your First Script
A script is a text file of Python code. Save this as ~/pyops/hostinfo.py:
#!/usr/bin/env python3
"""Print a short report about the machine this script runs on."""
import getpass
import os
import platform
import shutil
import socket
import sys
def main() -> None:
total, _used, free = shutil.disk_usage("/")
print(f"host: {socket.gethostname()}")
print(f"user: {getpass.getuser()}")
print(f"python: {platform.python_version()} ({sys.executable})")
print(f"system: {platform.system()} {platform.machine()}, {os.cpu_count()} CPUs")
print(f"disk /: {free / 2**30:.1f} GiB free of {total / 2**30:.1f} GiB")
if __name__ == "__main__":
main()
Each import line loads a module from the standard library, the large set of modules that comes with Python: socket knows the host name, shutil the disk usage, platform the system. def main() defines a function, the indented lines are its body (Python uses indentation, not braces, to group code), and the last two lines call main() when you run the file. Every later part explains these pieces properly; for now, run it:
The first line, #!/usr/bin/env python3, is the shebang. It runs the first python3 in your PATH, which is the virtual environment's while it is active, and the system's otherwise. For a script that must always use the project's environment (from cron, for example), call it as /home/dev/pyops/.venv/bin/python hostinfo.py, or make it self-contained with inline dependencies as shown in Part 6.
Python One-Liners for the Terminal
Python also runs code straight from the command line. Three forms are worth knowing on day one:
python -m module runs a standard library module as a program. Others you will use: python -m http.server 8000 serves the current directory over HTTP (handy for testing, never for production), python -m venv creates virtual environments, and python -m pip runs the pip that belongs to that exact Python.
Pick an Editor
Any editor works, but one that understands Python saves time: it shows errors as you type, completes names and runs the tests.
- Visual Studio Code with Microsoft's Python extension, plus the Ruff extension for linting and formatting. Use "Python: Select Interpreter" and choose
~/pyops/.venv, so the editor sees the same packages as your terminal. - PyCharm from JetBrains, which detects the
.venvdirectory on its own. - Vim, Neovim, Emacs or Helix with a language server such as Pyright or the one built into Ruff.
Common Mistakes
sudo pip install ...on a server. It mixes your packages with the onesaptordnfmanages and can break system tools. Use a virtual environment, oruv tool installfor command-line tools (Part 6).- Typing
pythonon Debian or Ubuntu and getting "command not found". Those systems only shippython3(thepython-is-python3package adds the short name). Inside an activated virtual environment,pythonalways works. - Running a script with the wrong Python. If an import fails with
ModuleNotFoundErrorfor a package you installed, checkwhich pythonand whether the environment is active. - Replacing or upgrading the system Python to get a newer version. Install the newer version next to it with uv, your package manager's extra packages, or Homebrew.
- Using Python 3.10 or older for new work. It no longer gets security fixes.
- Saving a script with Windows line endings (CRLF). Python itself does not mind, but the shebang line then names a program called
python3followed by a carriage return, which does not exist. Save scripts with LF line endings (every code editor has a setting), or convert them withdos2unix hostinfo.py(in the package manager of every Linux distribution and in Homebrew):
Summary
- Python 3.14 is the version this guide uses; 3.15 is out since 9 October 2026, and 3.10 reached end of life on 1 October 2026.
- uv installs any Python version into your home directory, next to the system Python, without
sudo. piprefuses to install into a distribution's Python (PEP 668). Use a virtual environment; on Debian and Ubuntu, installpython3-venvfirst.- The guide's project lives in
~/pyopswith a virtual environment in.venv; activate it withsource .venv/bin/activate. pythonstarts the REPL,python file.pyruns a script, andpython -m moduleruns a module such asjson.toolorhttp.server.
Next: Variables and Data Types, where you read settings from environment variables and learn why bool("false") is True.
Keep Learning
- Python 3.15 made UTF-8 the default: what changes on Linux servers when you upgrade.
- What Is Bash?: the shell you will run Python from, and where Bash stops being the right tool.
- The Python Fundamentals Quiz, to test yourself once you have worked through a few parts.
Tags
Found an issue?