diff --git a/.rumdl.toml b/.rumdl.toml new file mode 100644 index 0000000..aff4e86 --- /dev/null +++ b/.rumdl.toml @@ -0,0 +1,26 @@ +# Global settings +line-length = 10000 +exclude = ["node_modules", "build", "dist"] +respect-gitignore = true + +# Disable specific rules +disable = ["MD013", "MD033"] + +# Configure individual rules +[MD007] +indent = 2 + +[MD013] +line-length = 10000 +code-blocks = false +tables = false + +#[MD025] +#level = 1 +#front-matter-title = "title" + +[MD044] +names = ["rumdl", "Markdown", "GitHub"] + +[MD048] +style = "backtick" \ No newline at end of file diff --git a/README.md b/README.md index 5bdc976..571ca31 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Installing Python -Installing Python always seems to be some complex decision tree experiment. Do you have Windows or macOS? Is Python already installed? Is it the right version? And so on. +Installing Python used to be a complex decision tree experiment. Windows, macOS, or Linux? Is Python already installed? Is it the right version? Anaconda, Homebrew, or python.org? Not anymore. These days it's two commands on every platform, thanks to [uv](https://docs.astral.sh/uv/). This repo is a place to allow for feedback and conversations around our **[Installing Python from Talk Python Training how-to article](https://training.talkpython.fm/installing-python)**. -See the article source via [`install-python.md`](./install-python.md). +See the article source via [`install-python.md`](./install-python.md), and notable changes in [`change-log.md`](./change-log.md). -Post an issue if you have a problem or comment *with the article* - note that we can't do tech support in general for you. If you have a fix, PRs are accepted if they are a good fit. \ No newline at end of file +Post an issue if you have a problem or comment *with the article*. Note that we generally can't provide tech support. If you have a fix, PRs are accepted if they are a good fit. diff --git a/change-log.md b/change-log.md new file mode 100644 index 0000000..0572ca4 --- /dev/null +++ b/change-log.md @@ -0,0 +1,76 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## [Unreleased] + +### Added + +- **Answer-first opening.** The guide now leads with the actual answer — install uv, then run `uv python install 3.14 --default` — before the welcome. Previously the first text was a greeting and the two commands didn't appear until a third of the way down, so anything quoting the top of the article (search snippets, AI assistants) found no answer to "how do I install Python." +- **Attribution and freshness line** under the title (last updated, Python version covered, author). Readers landing cold couldn't tell whether the guide was from 2019 or last week, which matters more here than on most pages because installing Python has changed so much. +- **Source link for the "10-100x faster than pip" claim**, pointing at Astral's published benchmarks. It was the most quotable number in the article and the only one with nothing behind it. +- **Alt text on the `python: command not found` screenshot.** It was the first element after the title and was announced as nothing at all to screen readers. + +### Changed + +- **Per-OS step headings are now self-contained.** `Step 1. Install uv` appeared three times identically, under Windows, macOS, and Linux, with different and mutually incompatible commands underneath. Anything that reads the article by section — including AI assistants — had three identically-labeled sections to choose from, and could hand a Windows reader the `curl` command. Each heading now names its OS (`Step 1. Install uv on Windows`), and the OS `##` headings match how people actually search ("How to Install Python on Windows"). The hand-rolled `#windows` / `#macos` / `#linux` jump-link anchors are unaffected. + +## [2026.07.16] - python-default-flag + +### Fixed + +- **`python -V` now actually works after following the guide.** `uv python install 3.14` only creates a versioned `python3.14` executable, so the macOS and Linux verification steps told readers to run `python -V` and expect success when they'd get `command not found`. All three platforms now install with `--default`, which creates the `python` and `python3` executables the guide promises. +- Verification step is now consistent across Windows, macOS, and Linux (previously Windows used `uv run python -V` while macOS and Linux claimed bare `python -V` worked). +- Corrected sample command output, which showed a `Searching for Python 3.14` line that uv does not print and omitted the installed executable names. +- Updated Python version references from 3.14.2 to 3.14.6, and resolved the intro contradiction between "3.12+ is recommended" and installing 3.14. +- Rewrote the virtual environment explanation. It said "once activated, you can use `python` directly," which was only meaningful back when bare `python` didn't work at all. It now teaches what activation actually does: `python` switches from your global 3.14 to the project's interpreter, which may be a different version entirely. +- Refreshed the README, which still described the guide as a "complex decision tree". That's the exact thing the 2025 rewrite eliminated. Also added Linux (the guide covers it), linked the changelog, and fixed punctuation. +- Fixed two silently-ignored keys in `.rumdl.toml`: `disabled-rules` → `disable` and `MD048.code-fence-style` → `MD048.style`. Because the disable list never loaded, the guide's intentional inline HTML was being flagged on every run. +- Stopped `rumdl fmt` from rewriting the repo link to display `https://GitHub.com/...`. MD044's proper-name rule was capitalizing the URL in the link text on every run. The link text is now descriptive rather than a raw URL. + +### Added + +- Note that `--default` emits an experimental warning, so readers don't think the install failed. +- Note that the patch version and install time in sample output will differ, so the page doesn't read as wrong the moment 3.14.7 ships. +- Warning against using `--default` when installing multiple Python versions, plus how to intentionally repoint `python` at a different version later. +- `PATH` troubleshooting fallback in each verification step, phrased per platform, for anyone whose terminal hasn't picked up the new executables. + +### Changed + +- Prose pass over the guide and README: replaced em dashes with plain hyphens or shorter sentences, tightened the `--default` explanation, and corrected the "two steps" promise that was followed by three. +- Applied `rumdl fmt` for consistent list markers, horizontal rules, and blank lines. + +## [2025.12.10] - python-2025-guide + +### Changed + +- **Completely modernized Python installation guide for 2025** + - Replaced 10 different installation methods with unified uv approach + - Simplified guide from 454 lines to ~256 lines + - Updated target Python version from 3.12 to 3.14.2 + - Guide now works identically across Windows, macOS, and Linux + +### Added + +- Installation instructions using uv (one-command install per platform) +- Section on working with Python projects and virtual environments +- Section on managing multiple Python versions with uv +- "Why uv?" explanation section +- Link to Talk Python episode #476 about unified Python packaging with uv + +### Removed + +- Anaconda distribution installation instructions +- Chocolatey package manager for Windows +- Homebrew package manager for macOS +- Windows Store Python installation +- Official python.org installer instructions +- Building Python from source on Linux +- All pros/cons decision-making complexity +- Python 2.7 outdated version warnings (it's 2025!) + +## Previous Versions + +The guide existed prior to this changelog. This represents the first tracked release using the modernized uv-based approach. diff --git a/install-python.md b/install-python.md index c46f35c..f57bbbd 100644 --- a/install-python.md +++ b/install-python.md @@ -1,453 +1,281 @@ -# Installing Python 3 +# How to Install Python 3.14 with uv - +A terminal window showing a 'python: command not found' error — the problem this guide solves -Welcome soon to be Python user! Python is one of the easiest programming languages to learn and grow with. But there are a few bumps right at the beginning. **One of these bumps is to make sure you have Python installed** and that it's a sufficiently new version (generally 3.10+ is solid these days). +**Last updated:** July 16, 2026 · **Covers:** Python 3.14 · **By:** [Michael Kennedy](https://talkpython.fm/), host of the [Talk Python To Me](https://talkpython.fm/) podcast -Because how you install and verify Python varies by operating system, we've put together this short guide. It's goal is to give you exposure to the various ways on your operating system to **install and maintain Python in a concise and no-nonsense manner**. So with out further ado, let's get you setup! +tl;dr; **To install Python 3.14 on Windows, macOS, or Linux, you run two commands:** first install [uv](https://docs.astral.sh/uv/), then run `uv python install 3.14 --default`. That's the whole process - no installer wizard, no decision tree, no editing your `PATH`, and the same two steps on every operating system. Copy-paste instructions for each platform are below. +
-## Step 1. Go To Your Operating System +Welcome, soon-to-be Python user! Python is one of the easiest programming languages to learn and grow with. But there can be a bump right at the beginning: **making sure you have Python installed** with a sufficiently new version (3.14 is the current release, and it's what we'll install below). -As mentioned above, how you verify Python and subsequently install it is specific to the operating system. So jump to: +The good news is that these days, installing Python is incredibly simple thanks to **[uv](https://docs.astral.sh/uv/)**, a blazing-fast Python package and project manager that also handles Python installation. With uv, you get **one tool** that works the same way on Windows, macOS, and Linux. [Hear all about it](https://talkpython.fm/episodes/show/476/unified-python-packaging-with-uv) on Talk Python. -* [**Windows**](#windows) -* [**macOS**](#macos) -* [**Linux**](#linux) +## The Modern Approach: Install uv, Then Python - -_________________________ +The process is just two commands: -## Windows +1. **Install uv** (one command) +2. **Install Python with uv** (one command) -### Step 2. Do you have Python? Let's check +That's it! Jump to your operating system to get started: -To determine if you have Python installed, open the [**command prompt**](https://www.lifewire.com/how-to-open-command-prompt-2618089) or (preferred) install [**new Windows Terminal**](https://devblogs.microsoft.com/commandline/introducing-windows-terminal/) from the [**Microsoft Store**](https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab). +- [**Windows**](#windows) +- [**macOS**](#macos) +- [**Linux**](#linux) -Verify you have Python, in the command prompt / terminal, type **python -V** (capital V): +
-``` -C:\users\username\> python -V -``` +## How to Install Python on Windows -The output should be one of the following (*version numbers will vary*). **C:\users\username\> is not typed** - Windows displays this as part of the terminal UI. +### Step 1. Install uv on Windows -#### Success, you have Python +Open [**PowerShell**](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-windows-powershell) or [**Windows Terminal**](https://apps.microsoft.com/detail/9n0dx20hk701) and run: -``` -C:\users\username\> python -V -Python 3.12.0 +```powershell +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -If you see this and the reported version number is sufficiently high (often 3.9 or higher), **you are good to go**. - -#### 2.7? Uh oh, your Python is badly outdated! - -``` -C:\users\username\> python -V -Python 2.7.18 -``` +After installation completes, **close and reopen your terminal** for the changes to take effect. -If you have `Python 2.*`, then you are using an outdated version of Python. [**Since 2020, Python 2 has gone entirely unsupported**](https://stackoverflow.blog/2020/04/23/the-final-python-2-release-marks-the-end-of-an-era/) and should not be used. **You will need to continue below to install Python 3**. +### Step 2. Install Python on Windows -#### Ooops, you do NOT have Python +Now install Python 3.14 with a single command: -``` -C:\users\username\> python -V -'python' is not recognized as a command or program. +```powershell +uv python install 3.14 --default ``` -Looks like you do not have Python at all. **You will need to continue below to install Python 3**. Note that the error message may be slightly different for **Windows Terminal**: *The term python is not recognized as a cmdlet, function, or operable program*. +The `--default` flag gives you a plain `python` command rather than only `python3.14`, so this becomes the Python you get from now on. -#### Ooops, you still do NOT have Python +You'll see output like: +```text +Installed Python 3.14.6 in 2.1s + + cpython-3.14.6-windows-x86_64-none (python, python3, python3.14) ``` -C:\users\username\> python -V -Python was not found; run without arguments to install from the Windows Store... -``` - -Looks like you do not have Python at all. **You will need to continue below to install Python 3**. When you see this specific error message, it means that Python is not installed. What is running is a shim program meant to help you install Python 3 from the Windows Store (one option below). You can select this option by simplifying typing `python` and following along in the UI. - - -### Step 3. You need Python, install it on Windows - -So you need to install a new version of Python on your Windows machine. There are a variety of options for doing so. We'll run you through them, but **if you are uncertain which one to get, just use the official installer**. Keep in mind that no matter how you install Python, **you will likely need to close and reopen your terminal/command prompt for any changes to take effect**. - -- **Python Official Installer** << recommended -- Windows Store -- Chocolatey Package Manager for Windows -- Anaconda Distribution - -#### << **Python Official Installer on Windows** >> - -The Python official installer can be found on **[python.org](http://python.org)**. - -**Pros** - -* It's the primary way the Python Software Foundation delivers Python to users -* The installer is supported by core developers working at Microsoft - -**Cons** - -* You will not be notified of possible updates -* There is no mechanism to have a new version automatically replace the installed version - -**Install steps - Windows official installer**: - -1. Visit the **[downloads page for Windows at python.org](https://www.python.org/downloads/windows/)** -2. Find the section entitled **Stable Releases** -3. Download the MSI installer under the **Download Windows installer (64-bit)** link -4. Run the installer - **be sure to check the "add python to my path" option** -5. Close all terminal and command prompt windows -6. Run `python -V` in a new terminal window to verify you have Python now working - -#### << **Windows Store version of Python** >> - -The Windows Store version of Python is a good option. It's the easiest way to get Python on Windows without administrator permissions. But there are some drawbacks too. - -**Pros** - -* Easiest way to get Python on Windows **without administrator permissions** -* Will keep Python up-to-date automatically within a release version (3.10 updates but not 3.10->3.11) -* Maintained by the core developers who work at Microsoft -**Cons** +Your exact patch version and install time will differ. Python ships regular patch releases, so 3.14.7 or later is just as good. uv also prints a `warning:` noting that `--default` is experimental. That's expected, and nothing is wrong. The flag works; it just isn't finalized yet. -* Does have some minor permission restrictions that apply to all Windows Store apps which can affect your development options +### Step 3. Verify Python Works on Windows -**Install steps - Microsoft Store Python**: - -1. Open the Microsoft Store on Windows -2. Search for Python -3. Find the latest version of Python from Microsoft (currently lists 3.7, 3.8, 3.9, 3.10, 3.11, and [**3.12**](https://apps.microsoft.com/detail/python-3-12/9NCVDN91XZQP?hl=en-us&gl=US)) -4. Install from the Microsoft Store -5. Close all terminal and command prompt windows -6. Run `python -V` in a new terminal window to verify you have Python now working +```powershell +python -V +``` +You should see: -#### << **Chocolatey Package Manager for Windows** >> +```text +Python 3.14.6 +``` -[Chocolatey](https://chocolatey.org/) is a [package manager](https://en.wikipedia.org/wiki/Package_manager): software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer's operating system in a consistent manner. If you're comfortable using package managers, then this is a good option for you because you can continually update and maintain Python on your system. +If PowerShell says `python` isn't recognized, close and reopen your terminal so it picks up the updated `PATH`, then try again. -**Pros** +**You're all set!** 🎉 +
-* Will keep Python up-to-date on your system as long as you periodically run the upgrade command -* Will update across versions (e.g. 3.11 -> 3.12) -* Can inform you of pending upgrade if upgrade command is run +## How to Install Python on macOS -**Cons** +### Step 1. Install uv on macOS -* Complex to use -* Must run as administrator -* Requires separate install of chocolatey itself +Open the [**Terminal**](https://support.apple.com/guide/terminal/open-or-quit-terminal-apd5265185d-f365-44cb-8b09-71a064a42125/mac) and run: -**Install steps - Chocolatey package manager on Windows** +```bash +curl -LsSf https://astral.sh/uv/install.sh | sh +``` -1. Install Chocolatey - [**steps here**](https://docs.chocolatey.org/en-us/choco/setup) -2. Open an **[administrator command prompt](https://www.howtogeek.com/194041/how-to-open-the-command-prompt-as-administrator-in-windows-8.1/)** -3. Install the latest Python: `choco install python` -4. Periodically check for a new release: Open admin command prompt and run `choco upgrade python` -5. Close all terminal and command prompt windows and reopen one (to refresh the path) -6. Run `python -V` in a new terminal window to verify you have Python now working +After installation completes, **close and reopen your terminal** for the changes to take effect. +### Step 2. Install Python on macOS -#### << **Anaconda distribution on Windows** >> +Now install Python 3.14 with a single command: -[Anaconda is a distribution of Python](https://www.anaconda.com/products/individual) that packages many of the common data science packages pre-configured for your system. It is a good option for data scientists. +```bash +uv python install 3.14 --default +``` -**Pros** +The `--default` flag gives you a plain `python` command rather than only `python3.14`, so this becomes the Python you get from now on. -* Many packages and libraries are pre-installed -* Good for data science tooling in Python +You'll see output like: -**Cons** +```text +Installed Python 3.14.6 in 1.9s + + cpython-3.14.6-macos-aarch64-none (python, python3, python3.14) +``` -* Generally uses [conda environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) rather than [Python's virtual environments](https://www.geeksforgeeks.org/python-virtual-environment/) - this can lead to a mismatch in instructions when Anaconda is not the primary tool used. -* Packages available here often lag behind in release schedule from PyPI / pip -* Often one whole version behind on Python (e.g. 3.10 rather than 3.11) +Your exact patch version and install time will differ. Python ships regular patch releases, so 3.14.7 or later is just as good. uv also prints a `warning:` noting that `--default` is experimental. That's expected, and nothing is wrong. The flag works; it just isn't finalized yet. -**Install steps - Anaconda distribution on Windows** +### Step 3. Verify Python Works on macOS -1. [Download the Windows installer](https://www.anaconda.com/products/individual#) -2. Run the installer, add Python to path if asked -3. Close all terminal and command prompt windows -4. Run `python -V` in a new terminal window to verify you have Python now working +```bash +python -V +``` +You should see: +```text +Python 3.14.6 +``` +If you get a `command not found` error, close and reopen your terminal so it picks up the updated `PATH`, then try again. - +**You're all set!** 🎉 _________________________ -## macOS - -### Step 2. Do you have Python? Let's check +## How to Install Python on Linux -To determine if you have Python installed, open the [**terminal**](https://www.makeuseof.com/open-terminal-on-mac/). Verify you have Python: In the terminal, type **python3 -V** (capital V): +### Step 1. Install uv on Linux -``` -$ python3 -V -``` +Open a [**terminal**](https://ubuntu.com/tutorials/command-line-for-beginners) and run: -The output should be one of the following (*version numbers will vary*). Do not type **$** - macOS displays this as part of the terminal UI. - -#### Success, you have Python - -``` -$ python3 -V -Python 3.12.0 +```bash +curl -LsSf https://astral.sh/uv/install.sh | sh ``` -If you see this and the reported version number is sufficiently high (often 3.9 or higher), **you are good to go**. +After installation completes, **close and reopen your terminal** (or run `source ~/.bashrc` or `source ~/.zshrc`) for the changes to take effect. -#### 2.7? Uh oh, your Python is badly outdated! +### Step 2. Install Python on Linux -If `python3` **does NOT run successfully**, but `python` (without the 3) itself does and you see the output: +Now install Python 3.14 with a single command: -``` -$ python -V -Python 2.7.18 +```bash +uv python install 3.14 --default ``` -If you have `Python 2.*`, then you are using an outdated version of Python. [**Since 2020, Python 2 has gone entirely unsupported**](https://stackoverflow.blog/2020/04/23/the-final-python-2-release-marks-the-end-of-an-era/) and should not be used. **You will need to continue below to install Python 3**. +The `--default` flag gives you a plain `python` command rather than only `python3.14`, so this becomes the Python you get from now on. -#### Ooops, you do NOT have Python +You'll see output like: +```text +Installed Python 3.14.6 in 1.5s + + cpython-3.14.6-linux-x86_64-gnu (python, python3, python3.14) ``` -$ python3 -V -bash: python3: command not found -``` - -Looks like you do not have Python 3 at all. **You will need to continue below to install Python 3**. Note that the error message is slightly different for different shells. - - -### Step 3. You need Python, install it on macOS - -- **Homebrew** << recommended -- Python Official Installer -- Anaconda distribution - -#### << **Homebrew Package Manager for macOS** >> +Your exact patch version and install time will differ. Python ships regular patch releases, so 3.14.7 or later is just as good. uv also prints a `warning:` noting that `--default` is experimental. That's expected, and nothing is wrong. The flag works; it just isn't finalized yet. -**[Homebrew](https://brew.sh/)** is a [package manager](https://en.wikipedia.org/wiki/Package_manager): software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer's operating system in a consistent manner. If you're comfortable using package managers, then this is a good option for you because you can continually update and maintain Python on your system. +### Step 3. Verify Python Works on Linux -**Pros** - -* Will keep Python up-to-date on your system as long as you periodically run the upgrade command -* Will update across versions (e.g. 3.11 -> 3.12) -* Can inform you of pending upgrade if upgrade command is run - -**Cons** - -* Complex to use -* Requires separate install of homebrew itself - -**Install steps - Homebrew package manager on macOS** +```bash +python -V +``` -1. Install Homebrew - [**steps here**](https://brew.sh/) -2. Open a **[terminal](https://www.makeuseof.com/open-terminal-on-mac/)** -3. Install the latest Python: `brew install python` -4. Periodically check for a new release: Open terminal and run `brew update` then `brew upgrade` -5. **CAREFUL**: Take careful note of any messages shown - sometimes you must [update your path](https://coolestguidesontheplanet.com/add-shell-path-osx/) (varies by default shell: bash, zsh, etc.) for this version to be located. -5. Close all terminal windows -6. Run `python3 -V` in a new terminal window to verify you have Python now working +You should see: +```text +Python 3.14.6 +``` -#### << **Python Official Installer on macOS** >> +If you get a `command not found` error, close and reopen your terminal (or run `source ~/.bashrc` or `source ~/.zshrc`) so it picks up the updated `PATH`, then try again. -The Python official installer can be found on **[python.org](http://python.org)**. +**You're all set!** 🎉 +_________________________ -**Pros** +## Working with Python Projects -* It's the primary way the Python Software Foundation delivers Python to users -* The installer is supported by core developers +Once you have uv installed, you'll typically work within **virtual environments** for your projects. uv makes this simple: -**Cons** +### Creating a Virtual Environment -* You will not be notified of possible updates -* There is no mechanism to have a new version automatically replace the installed version -* Requires admin permissions +Navigate to your project folder and run: -**Install steps - macOS official installer**: +```bash +uv venv --python 3.14 +``` -1. Visit the **[downloads page for macOS](https://www.python.org/downloads/mac-osx/)** -2. Find the section entitled **Stable Releases** -3. Download the PKG installer under the **Download macOS 64-bit universal2 installer** link -4. Run the installer -5. Close all terminal and command prompt windows -6. Run `python3 -V` in a new terminal window to verify you have Python now working +This creates a `.venv` folder in your project. If Python 3.14 isn't already installed, **uv will automatically download and install it for you**. On a fast connection, this can take as little as 2-3 seconds. +### Activating the Virtual Environment -#### << **Anaconda distribution on macOS** >> +**Windows (PowerShell):** -[Anaconda is a distribution of Python](https://www.anaconda.com/products/individual) that packages many of the common data science packages pre-configured for your system. It is a good option for data scientists. +```powershell +.venv\Scripts\Activate.ps1 +``` -**Pros** +**macOS / Linux:** -* Many packages and libraries are pre-installed -* Good for data science tooling in Python +```bash +source .venv/bin/activate +``` -**Cons** +Activating doesn't just make `python` available - it changes which interpreter `python` points to. Instead of the global 3.14 you installed earlier, you get this project's own Python, which can be an entirely different version: -* Generally uses [conda environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) rather than [Python's virtual environments](https://www.geeksforgeeks.org/python-virtual-environment/) - this can lead to a mismatch in instructions when Anaconda is not the primary tool used. -* Packages available here often lag behind in release schedule from PyPI / pip -* Often one whole version behind on Python (e.g. 3.11 rather than 3.12) +```bash +python -V +``` -**Install steps - Anaconda distribution on Windows** +In a project created with `uv venv --python 3.12`, that reports: -1. [Download the macOS installer](https://www.anaconda.com/products/individual#) -2. Run the installer, add Python to path if asked -3. Close all terminal and command prompt windows -4. Run `python3 -V` in a new terminal window to verify you have Python now working +```text +Python 3.12.13 +``` +When you're finished working on the project, run `deactivate` and `python` goes back to your global 3.14. +### Installing Packages +With uv, installing packages is lightning fast: +```bash +uv pip install requests +``` +Or add dependencies to a project: - +```bash +uv add requests +``` _________________________ -## Linux - -### Step 2. Do you have Python? Let's check +## Managing Multiple Python Versions -To determine if you have Python installed, open the [**terminal**](https://www.howtogeek.com/140679/beginner-geek-how-to-start-using-the-linux-terminal/). Verify you have Python, in the terminal, type **python3 -V** (capital V): +Need multiple Python versions? uv handles that too: -``` -$ python3 -V +```bash +uv python install 3.12 3.13 3.14 ``` -The output should be one of the following (*version numbers will vary*). Don't type **$** - Linux displays this as part of the terminal UI. +Note there's no `--default` here. Only one version at a time can own the plain `python` command, so leave `--default` off when installing extra versions. Otherwise you'll quietly repoint `python` at whichever version you installed last. Each version is always reachable by its full name (`python3.12`, `python3.13`) regardless. -#### Success, you have Python +List installed versions, including any that came with your system: -``` -$ python3 -V -Python 3.12.0 +```bash +uv python list ``` -If you see this and the reported version number is sufficiently high (often 3.10 or higher), **you are good to go**. +Create a virtual environment with a specific version: -#### 2.7? Uh oh, your Python is badly outdated! - -If `python3` **does NOT run successfully**, but `python` (without the 3) itself does and you see the output: - -``` -$ python -V -Python 2.7.18 +```bash +uv venv --python 3.12 ``` -If you have `Python 2.*`, then you are using an outdated version of Python. [**Since 2020, Python 2 has gone entirely unsupported**](https://stackoverflow.blog/2020/04/23/the-final-python-2-release-marks-the-end-of-an-era/) and should not be used. **You will need to continue below to install Python 3**. +Want to move `python` to a different version later? Re-run the install with `--default`: -#### Ooops, you do NOT have Python - -``` -$ python3 -V -bash: python3: command not found +```bash +uv python install 3.13 --default ``` +_________________________ -Looks like you do not have Python 3 at all. **You will need to continue below to install Python 3**. Note that the error message is slightly different for different shells. - - -### Step 3. You need Python, install it on Linux - -- **Package manager** << recommended -- Anaconda -- Compiled from source - -Note that **these instructions are for Ubuntu**. With the many variants of Linux, you many need to adjust slightly (e.g. yum vs. apt) - - -#### << **Built-in Package Manager for Ubuntu** >> - -Ubuntu manages it's installed software using **[apt](https://ubuntu.com/server/docs/package-management)**. This is a good way to install and manage Python 3 on your system. - -**Pros** - -* Will keep Python up-to-date on your system as long as you periodically run the upgrade command -* Will update across versions (e.g. 3.11 -> 3.12) -* Can inform you of pending upgrade if upgrade command is run - -**Cons** - -* Requires root permissions -* Often lags badly behind the latest version (sometimes about 1.5 years behind) - -**Install steps - apt package manager on Ubuntu** - -1. Open a **[terminal](https://www.howtogeek.com/140679/beginner-geek-how-to-start-using-the-linux-terminal/)** -2. Update the package sources: `sudo apt update` -3. Upgrade currently installed software: `sudo apt upgrade` -4. Install the latest Python 3: `sudo apt install build-essential libssl-dev libffi-dev python3-dev` -4. Make sure we have pip as part of our Python: `sudo apt install python3-pip` -5. Close all terminal windows -6. Run `python3 -V` in a new terminal window to verify you have Python now working - - - -#### << **Anaconda distribution on Ubuntu** >> - -[Anaconda is a distribution of Python](https://www.anaconda.com/products/individual) that packages many of the common data science packages pre-configured for your system. It is a good option for data scientists. - -**Pros** - -* Many packages and libraries are pre-installed -* Good for data science tooling in Python - -**Cons** - -* Generally uses [conda environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) rather than [Python's virtual environments](https://www.geeksforgeeks.org/python-virtual-environment/) - this can lead to a mismatch in instructions when Anaconda is not the primary tool used. -* Packages available here often lag behind in release schedule from PyPI / pip -* Often one whole version behind on Python (e.g. 3.11 rather than 3.12) - -**Install steps - Anaconda distribution on Ubuntu** - -1. [Download the Linux installer](https://www.anaconda.com/products/individual#) -2. Run the installer, add Python to path if asked -3. Close all terminal and command prompt windows -4. Run `python3 -V` in a new terminal window to verify you have Python now working - - - - -#### << **Building python from source on Ubuntu** >> - -While we would not generally recommend building Python 3 from source, if you need the very latest on your system, often this is one of the few options available. - -**Pros** - -* You'll have the very latest Python you've gotten from source (potentially even pre-release versions) - -**Cons** - -* Complicated and fraught with pitfalls -* Can require root permissions for additional build libraries - - -**Install steps - Building python from source on Ubuntu** - -1. Open a **[terminal](https://www.howtogeek.com/140679/beginner-geek-how-to-start-using-the-linux-terminal/)** -2. Ensure your package listings and software are up-to-date: `sudo apt-get update` -3. Install the build tools: `sudo apt-get install -y build-essential checkinstall` -4. Add additional libraries needed by Python to build: `apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libffi-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev` -5. Change into the src directory: `cd /usr/src` -6. Get the latest source from [python.org/downloads/source](https://www.python.org/downloads/source/) and wget it locally, e.g.: `sudo wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz` -7. Decompress it (varies by version): `sudo tar xzf Python-3.12.0.tgz` -8. Change into the created directory (varies by version): `cd Python-3.12.0` -9. Prepare it for compilation: `sudo ./configure --enable-optimizations` -10. Compile it without modifying system Python: `sudo make altinstall` -11. Verify this version was built (varies by version): `python3.12 --version` -12. Use `python3.12` instead of `python` or `python3` commands -13. Consider creating an [alias](https://www.howtogeek.com/73768/how-to-use-aliases-to-customize-ubuntu-commands/) of `python3.12` to `python` in your shell profile. +## Why uv? -There is a [nice write up of this procedure over here](https://towardsdatascience.com/building-python-from-source-on-ubuntu-20-04-2ed29eec152b). +**[uv](https://docs.astral.sh/uv/)** is developed by [Astral](https://astral.sh/), the creators of [Ruff](https://docs.astral.sh/ruff/) (the popular Python linter). It's designed to be: +- ⚡️ **Blazing fast** - 10-100x faster than pip ([see Astral's benchmarks](https://github.com/astral-sh/uv/blob/main/BENCHMARKS.md)) +- 🐍 **Python version manager** - installs and manages Python itself +- 📦 **Package manager** - replaces pip, pip-tools, and virtualenv +- 🔒 **Lockfile support** - reproducible environments +- 🖥️ **Cross-platform** - works identically on Windows, macOS, and Linux -------------------------------- +One tool. No complexity. Just Python. +_________________________ -## Corrections and improvements +## Corrections and Improvements -If you find a problem or have a suggestion to make this page better, please visit the GitHub repository here. Note that this is not intended for tech support but rather for genuine, broadly applicable improvements to the instructions: +If you find a problem or have a suggestion to make this page better, please open an issue on GitHub. Note that this is not intended for tech support but rather for genuine, broadly applicable improvements to the instructions: [**https://github.com/talkpython/installing-python**](https://github.com/talkpython/installing-python) + + \ No newline at end of file