Python
Update
Software
Tutorial
Programming

How to update Python?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Updating Python is not just about installing a newer interpreter. You also need to understand how Python was installed on your machine, because the correct upgrade path depends on whether you used the official installer, a system package manager, Homebrew, or a version manager such as pyenv.

That distinction matters because replacing the wrong interpreter can break scripts, editors, or operating system tools. The safest approach is to install the newer version alongside the old one, then point your projects to the version you actually want.

Check What You Have Now

Before changing anything, inspect the interpreter that your shell is using:

bash
1python --version
2python3 --version
3which python
4which python3

On some systems, python points to Python 2, on others it points to Python 3, and on many machines only python3 is guaranteed. You also want to know whether the executable lives under a system directory, Homebrew path, or a version manager directory.

If you are using virtual environments, activate one and check again. A virtual environment may hide the system interpreter path.

Update Using the Same Tool That Installed Python

The main rule is simple: use the same installation channel you already rely on.

If you installed Python with Homebrew on macOS:

bash
brew update
brew upgrade python
python3 --version

If you manage versions with pyenv:

bash
pyenv install 3.12.8
pyenv global 3.12.8
python --version

If you are on Linux and use the distribution package manager, update through that package manager rather than replacing files manually. For example, Debian-based systems commonly use:

bash
sudo apt update
sudo apt install python3
python3 --version

On Windows or when using the official installer on macOS, the usual pattern is to run the newer installer and let it place the new interpreter alongside or above the previous one in your configured path.

Prefer Isolated Project Versions

For development, version managers are usually safer than changing the global interpreter. pyenv is popular because different projects can pin different versions without conflict.

Example:

bash
pyenv install 3.12.8
pyenv local 3.12.8
python --version

That writes a .python-version file for the current project. Team members can then reproduce the same interpreter version without guessing what your system default was.

Pair that with a virtual environment:

bash
python -m venv .venv
source .venv/bin/activate
python --version

This keeps interpreter upgrades separate from project dependencies.

Rebuild Environments After Upgrading

A new Python interpreter does not automatically migrate all your installed packages or virtual environments. In many cases, the cleanest path is:

  1. install the new interpreter
  2. create a fresh virtual environment
  3. reinstall dependencies from requirements.txt or pyproject.toml

Example:

bash
python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

This avoids subtle ABI or path issues that can happen when you try to reuse an environment built with an older interpreter.

Verify Which Python Your Tools Use

After updating, check your editor, CI jobs, cron jobs, and shell aliases. It is common to upgrade Python successfully and still have pip, VS Code, or a task runner pointing at the old interpreter.

Useful checks:

bash
python -m pip --version
pip --version

If those point to different locations, prefer python -m pip so the package installer matches the interpreter you intend to use.

Common Pitfalls

  • Upgrading the system Python directly and breaking OS-managed scripts.
  • Installing a new version but still using the old one because the shell path did not change.
  • Reusing an old virtual environment with a new interpreter and hitting package compatibility issues.
  • Using pip without checking which interpreter it belongs to.

Summary

  • First identify how Python was installed on your machine.
  • Update it using the same tool or package manager that installed it.
  • Prefer version managers and virtual environments for development work.
  • Recreate project environments after an interpreter upgrade instead of patching them in place.
  • Verify your shell, editor, and pip are all pointing at the Python version you expect.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.