Kiến Thức Linux

How to Upgrade Python to 3.9

How to update Python on Windows, Linux and Max - a tutorial.

Introduction

Every fresh Python release comes with bug fixes and new features. Python 3.12, the latest point release when this article was written, comes with features such as flexible f-string parsing, support for the buffer protocol, a new debugging/profiling API, and many performance improvements.

This tutorial shows you how to update Python to the latest version on all the major operating systems – Windows, macOS, and Linux.

How to update Python on Windows, Linux and Max - a tutorial.How to update Python on Windows, Linux and Max - a tutorial.

Prerequisites

  • Administrative rights on the operating system you are using.
  • Knowledge of which Python version is currently on your system (refer to How to Check Python Version for instructions).

Note: If you are upgrading from a Python 2 release and do not have Python 3 installed, read our comprehensive guides on how to install it on:

Update Python on Windows

There are three ways to update Python on Windows: via the Python installer, using Chocolatey, or installing the app from the Microsoft Store.

via Python Installer

The Python installer is available on the official Python website. Follow the steps below to install it:

1. Launch a browser and visit the Python Releases for Windows page. Click the Latest Python 3 Release link to download the installation file on your computer.

Download latest Python release for Windows.Download latest Python release for Windows.

2. Scroll down to the Files section and select the 32-bit or 64-bit installer, depending on your architecture. In this tutorial, we will use 64-bit.

Download the Python installer for Windows.Download the Python installer for Windows.

3. Next, run the Python installer. Select Install Now to install Python with the recommended options, or select Customize Installation to pick the install location and features. Check the Add python.exe to PATH checkbox to run Python scripts and access Python packages from any directory using the command prompt.

Install the latest Python version on Windows.Install the latest Python version on Windows.

4. When the installation finishes, check whether the new Python version has been installed successfully. Open Windows PowerShell and type:

python --version

The output should show the latest version of Python, as in the image below.

Check the Python version on Windows.Check the Python version on Windows.

via Chocolatey

Chocolatey is a command-line package manager for Windows. Follow the steps below to update Python using Chocolatey:

1. Open the Windows PowerShell or Command Prompt and run the following command:

choco find python
Find available Python packages using Chocolatey.Find available Python packages using Chocolatey.

The command outputs all the packages containing the keyword Python. You can install any package from the list. In this tutorial, we will install the latest version.

2. Run the following command to update your Python app:

choco install python
Install the latest Python version using Chocolatey.Install the latest Python version using Chocolatey.

To install a different version, specify the version number in the package name.

via Microsoft Store

If you want to use the latest Python version to learn the basics or test some simple concepts, find and install the Python app from the Microsoft Store.

1. Open the Microsoft Store and type Python in the search field. Select the latest Python version from the search results that appear. In our case, it is Python 3.12:

Download the latest Python version from the Microsoft Store.Download the latest Python version from the Microsoft Store.

2. Click the Get button to start the installation and wait for the process to complete.

Get the Python app on Microsoft Store.Get the Python app on Microsoft Store.

3. Start the interactive Python experience by finding the app in the Start Menu.

Update Python on Linux

This article uses Ubuntu Linux. If you are using a different Linux distribution, check the available installation methods for your system.

There are two ways to update Python on Linux Ubuntu: by installing the latest version available in the deadsnakes PPA or by compiling it from the source code.

Warning: Many Linux systems have Python 2 installed as the system version. Removing Python 2 could cause a system error. If you are planning to install Python 3 on Linux, install it alongside Python 2 and invoke it with the python3 command.

via PPA

The latest Python versions are available in the deadsnakes PPA. Follow the steps below to add the PPA to your system and update Python:

1. Add the PPA to your system by running the command below:

sudo add-apt-repository ppa:deadsnakes/ppa
Add PPA repository for latest Python releases on Ubuntu.Add PPA repository for latest Python releases on Ubuntu.

The command adds the PPA to your system and lists the available Python versions for your system.

2. Install the latest Python version by running the command below:

sudo apt install python3.13
Install the latest Python version on Linux Ubuntu.Install the latest Python version on Linux Ubuntu.

When prompted, type y and press Enter to continue the installation. The latest available version for our system is Python 3.13. You can specify any of the available versions to install that one.

3. Check the program version after installation by running:

python3.13 --version
Checking Python version on Ubuntu.Checking Python version on Ubuntu.

The command outputs the installed Python version.

4. Next, install PIP for Python by running:

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.13

Make sure to replace the Python version in the command with the one you installed.

via Source Code

If the PPA doesn’t have the Python version you need, you can install it by compiling it from the source code. Follow the steps below:

1. Install the build libraries required for compiling Python from source code. Run the following command:

sudo apt install build-essential checkinstall 
libreadline-gplv2-dev  libncursesw5-dev libssl-dev 
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

2. Navigate to the /usr/src directory and download the Python source code using the wget command. Check the official Python source code page to ensure you compile the latest version. Run the commands below and replace the version numbers in the link with your own:

cd /usr/src 
sudo wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz

3. After the download finishes, extract the archive using the command below:

sudo tar xzf Python-3.12.0.tgz

Replace the version number in the command with the one you have downloaded.

4. Change the working directory to the one with the extracted source code and prepare it for compiling using the commands below:

cd Python-3.12.0
sudo ./configure --enable-optimizations

5. Compile the source code by running the following command:

sudo make altinstall

The process takes some time to complete. Wait until it finishes to start using the latest Python version.

Update Python on macOS

On macOS, Python can be installed, upgraded, and maintained using the command-line interface or the GUI.

via Python Installer

1. In your browser, navigate to the Python Releases for macOS page. Click the Latest Python 3 Release link to go to the installer downloads page.

Get the latest Python release for macOS.Get the latest Python release for macOS.

2. Scroll to the Files section and select the macOS universal installer to start the download.

Download macOS Python installer.Download macOS Python installer.

3. Run the downloaded installer and go through the installation steps. Click Continue, agree to the License, and confirm the installation location and type.

Install Python on macOS.Install Python on macOS.

4. Once the installation is complete, select Close.

Python installation on macOS complete.Python installation on macOS complete.

5. Finally, confirm that the new Python version has been successfully installed by running the following command in the terminal:

python3 --version

The output displays the latest Python version installed on your system.

Checking the python3 version on macOS.Checking the python3 version on macOS.

via Homebrew

Install Python in the macOS terminal using the Homebrew package manager. If you do not have Homebrew, install it by typing the following script in the terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Then, proceed with the steps:

1. Update Homebrew by running:

brew update

2. If you are upgrading from Python 2, install Python 3 with the command:

brew install python3

If you already have a version of Python 3 installed, upgrade the package with the brew upgrade command:

brew upgrade python3

Why Should You Update Python?

Since Python 3 was not a backward-compatible release, Python 2 has remained the version of choice for a long time for those who wanted a stable development environment. Some services, like Google App Engine, did not initially support Python 3.

However, given that the official support for the final Python 2.7 release has ended upgrading to Python 3 is now strongly recommended. Python 3 is faster, and its syntax is more user-friendly.

If you already work with Python 3, upgrading to the latest point release gives you all the security updates, bug fixes, and new features.

Conclusion

After reading this tutorial, you should know how to update your Python 3 version on Windows, macOS, and Linux.

To learn more about Python, read our article on Python data types.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !