How to Upgrade Python on Windows: A Comprehensive Guide

This article will explain the four ways to upgrade to a new version of Python on a Windows system: installer, Microsoft Store, Winget, and Chocolatey. You will also learn how to use different versions of Python on your system and how to uninstall an old version.

To follow along, you should be on a Windows computer and have Python installed. The examples in the article were tested on Windows 11.

Check the current Python version

Before we upgrade to the latest stable version of Python, version 3.12, you should check the version running on your machine. An upgrade may not be necessary.

Open a command prompt and run python as below to see the version you have installed

python --version

Checking Python’s version

Upgrade Python with the installer

In this section, you will learn how to upgrade Python using the official installer. Open the Python official website and download the latest stable version.

Run the installer by double-clicking the downloaded file in Explorer to start the installation process.

The Python installer setup file

A setup window should open up as below.

Configuring the installer

At the setup window, you can fine-tune the installation parameters. The key things to note are:

  • Enable the option to install py.exe with admin privileges. Py.exe is a Python launcher for Windows only, allowing you to easily execute Python scripts from the command line.
  • Check the option to add this version of Python to the PATH variable so you just type Python on the command line. Without this option, you may call Python by specifying its location.
  • The installation location and additional features
    • Install Now – This will install Python to the default location with the default suite of supporting software and configuration options.
    • Customize installation – Cherry-pick supporting software and set a custom installation location.

The setup window should now look like the shot below. You will notice a User Account Control (UAC) shield by Install Now, indicating that the installation will request admin privileges as it progresses.

Select options in the Python installer

Select options in the Python installer

Select Install Now to start.

At the UAC prompt, select Yes to elevate privileges and continue.

Elevating privileges for installation

The installation will end, as shown in the shot below.

Select Disable path length limit to ensure Python programs that deal with long paths can run error-free. This is Windows-specific. By default, Windows only allows you to use paths that are 260 characters or less.

Congratulations, you have just upgraded to Python 3.12. Confirm its presence by running py –version in PowerShell. The launcher defaults to the highest Python version available.

py --version

Checking the Python version

The older version, version 3.10, is still around. You can see that by running py with the list switch.

py --list

Listing installed Python versions

You can maintain various versions of Python on your system without causing any conflict. This approach lets you transition scripts slowly, after verifying them with the updated version.

Run the new Python version

As discussed earlier, initiating the new Python interpreter is as easy as running the py command. By default, the launcher chooses the topmost Python version it can locate on your system.

py

Running the new Python with Py

You can also specify a version with the launcher. For example, you can execute py as follows to launch version 3.10,

py -3.10

 

Running the old version with python

Running the old version with python

Running the new Python alongside Python 2

You can also start Python by executing the python command. However, when you start Python this way, you do not necessarily launch the latest Python. You launch the first available Python executable.

The system searches the folders listed in the Path variable and runs the first Python executable it can find. Path is a variable that contains a list of folders that should be searched when the shell is looking for an executable.

Two primary considerations influence the version that the python command initiates;

  • The sequence in which all the versions were installed
  • The adjustments that were implemented at the time of Python installation.

Automatically, these two variables change the Path variable and determine which version is discovered first.

For instance, on a system with Python 2.7, running python usually starts Python 2.7 instead of the freshly installed update.

python

Running the old version with python

You can confirm which python interpreter will be found first by using the where.exe command

where.exe python

Listing python executables with where.exe

For my machine, Python 2 is the first on the list. Yours may be different.

Because of this behavior, I prefer the launcher(py) to Python when launching Python. Py gives you more control and flexibility over which version will run.

When you cannot use the Py launcher, edit Path to ensure your preferred version of Python is found first. An example of such a situation is with third-party applications that are hard-coded to use python instead of py.

As a last resort, you can specify the full location of the Python executable to start a particular version. For example, instead of just typing python, type;

c:python27python.exe

Running Python with the full location

You can find out the full path for your Python installation with the where command as below;

where.exe python

Finding the location of your Python interpreter

Upgrade Python with Winget

Winget is a built-in command-line tool that streamlines and automates the installation of frequently used Windows programs. It functions as Microsoft’s package manager and is already pre-installed in several Windows versions. It is akin to an apt package manager in Ubuntu.

Launch PowerShell and execute the winget command as specified below, to update Python:

winget install python.python.3.12

A progress bar should appear, indicating the search and download progress of the setup files.

Upgrading Python with Winget

After the download, a graphical Setup progress window should automatically pop up as Python is being installed.

Viewing installation progress

You will be automatically redirected to PowerShell with a success notice upon completion.

Completing the installation successfully

Completing the installation successfully

You can also install the python launcher via winget as follows

winget install python.launcher

Installing the launcher via Winget

Installing the launcher via Winget

Upgrade Python with Microsoft Store

Another way to upgrade Python is by installing it from the Microsoft Store app on your desktop. The store hosts multiple versions of Python’s interpreter.

Select the Microsoft Store app from the taskbar to open up the store.

Launching the Microsoft Store

Search for python to bring up a list of all versions available in the store. Select Get on the version you require (3.12) to kick off the installation.

Searching for Python

Installing Python from the Microsoft Store

After the installation, you can use Python 3.12 by typing in python3.12 in a terminal.

“`html

Starting Python with appended version number

Python from the store does not come with a Py launcher. Instead, it enables you to launch Python with the version number as above. This is unique to installations from the Microsoft Store.

You can launch Python with the python command as well. This depends on the value of your Path variable.

“`

Starting Python with the python command

Note: If typing python at the command line opens up Microsoft Store instead,

  1. Open App execution Aliases from the Start Menu
  2. Ensure the aliases for Python 3.12 point to python3.exe and python.exe respectively.
  3. Ensure the aliases for Python 3.12 are turned On.

Enabling app execution aliases

Enabling app execution aliases

Upgrade Python with Chocolatey

Chocolatey is a third-party package manager that makes installing many applications from the command line easy. If you already have Chocolatey installed, installing Python is as simple as executing the one-liner below in an elevated terminal window.

choco install python -y

Installing Python with Chocolatey

The -y switch completes the execution without further user interaction. Chocolatey’s Python installation installs the launcher alongside. It also edits the Path variable to help the system first find the newly installed Python.

To use Python immediately, just restart PowerShell.

Next, type python or py to start up the most recently installed version.

“`

Starting Python

You can also upgrade to a specific version as follows

choco install python311

“`

Uninstall the old version of Python

The most straightforward way to install Python is to go to Settings -> Apps -> Apps and Features. Regardless of the installation method, you will likely find most Python installations listed here.

Listing installed Python versions in Apps and features

Select the version you want to remove and click Uninstall.

Uninstalling Python via Apps and features

You can also uninstall Python with the package managers you used to install them as below;

Subscribe to 4sysops newsletter!

choco uninstall python312

winget uninstall python.python.3.12

Conclusion


Posted

in

, ,

by

Tags: