Keeping your Python programming language up to date is essential for taking advantage of the latest features, improvements, and security fixes. As a Python programmer, you’ll want to make sure you’re using the most recent version to ensure optimal performance and compatibility with other libraries and frameworks.
To update Python on Windows and macOS, you can download the latest version from the official Python website, run the installer, and follow the prompts. If you’re using Linux, you can add the deadsnakes PPA, update your apt cache, and install the updated Python package.
But.
And there is always a but.
Keeping your Python installation current ensures you’re leveraging the full potential of the language. In this article, we’ll go over how to update Python on Windows, macOS, and Linux. For each operating system, we’ll outline the steps that you will need to update Python to the latest version.
Let’s get into it!
How to Check Your Current Python Version
Before updating Python, it’s essential to know your current version of Python. You can easily check the Python version on your computer via the command line.
This process varies slightly depending on your operating system.
How to Check Current Python Version on Windows
To check the current Python version on Windows, you can follow the steps given below:
- Press Win + R, type cmd, and hit Enter to open the Command Line Interface.
- Type python –version and press Enter. You should see your Python version displayed as shown in the image below:
This command will print the current Python version onto the terminal. As you can see in the image above, I am using the Python version 3.10.2.
How to Check Python Version on Mac and Linux
To check the current Python version on Mac and Linux, you can follow the steps given below:
- Open the Terminal (Press Ctrl+Alt+T on Linux).
- Type python3 –version and press Enter to display your Python 3 version. Alternatively, you may use python3 -V.
In both Windows and Mac/Linux, the output will look something like this:
Python 3.10.2
Now that you know your current version, you can proceed with updating it if necessary.
In the next section, we’ll look at the process of updating Python to the latest version.
How to Update Python on Windows
In this section, you’ll learn how to update Python on your Windows computer using three different methods:
- Using the Python installer
- Using the Windows Microsoft Store
- Using Chocolatey
1. Using the Python Installer
To upgrade Python on your Windows system using the Python installer, follow these steps:
- Visit the Python Releases for Windows section on Python’s official website to find the desired version of Python.
- Click the Download Python button to download the installation file for the version you want, such as Python 3.11.
- Run the downloaded installer. If you’re upgrading from an existing Python 3.x installation, the installer will allow you to install the newer version alongside the older one.
- During the installation process, ensure that the “Add Python to PATH” option is checked, so the new version is available in your system’s PATH.
- Finally, open a command prompt (cmd) and type py.exe to verify that Python has been updated successfully.
Once you carry out all the steps outlined above, you’ll be able to use new features that come with the latest versions.
2. Using the Windows Microsoft Store
Another option to update Python is through the Windows Microsoft Store.
You can follow the steps below if you’d like to update Python using the Windows Microsoft Store:
- Open the Microsoft Store on your Windows system and search for “Python.”
- Choose the Python version you want to install, such as Python 3.11.
- Click Get or Install to start the installation process.
- Once the installation is complete, you can find Python in the Start Menu.
- Open a command prompt (cmd) and type py.exe to verify that the new Python version has been installed successfully.
3. Using Chocolatey to Update Python
Chocolatey is a package manager for Windows that can help you update Python with ease.
You can follow the steps given below to update Python using Chocolatey:
- Install Chocolatey on your computer if you haven’t already. To do this, launch PowerShell as an administrator and run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((Invoke-WebRequest -Uri 'https://chocolatey.org/install.ps1' -UseBasicParsing).Content)
This Python command will install the Chocolatey package manager on your operating system.
- Once Chocolatey is installed, you can upgrade Python by running the following command in an elevated PowerShell window:
choco install python --pre
This will install the latest pre-release version of Python, such as Python 3.11.
- To keep your Python installation up-to-date in the future, simply run:
choco upgrade python
This command will update Python to the latest Python version if you already have Python installed:
- Verify that Python has been updated by opening a command prompt (cmd) and typing py.exe.
You can see that our old version of Python got updated to the latest version, from 3.10 to 3.11.
By following the instructions for one of these methods, your Python installation on Windows should be up-to-date and ready for you to use in your development environment.
How to Update Version of Python on MacOS
In this section, we’ll discuss two methods to update Python to the latest Python version on your MacOS: using the Python.org installer and using Homebrew.
1. Using the Python Installer
To update Python using the Python.org installer, follow the steps below:
- Visit the Python.org website and navigate to the Downloads section.
- Click on the “Latest Python 3 Release” link to download the installer for the most recent version.
- Once the download is complete, open the installer and follow the prompts to start the installation process.
- Throughout the installation, ensure that you select the “Add Python to PATH” option to update your system’s PATH environment variable.
After a successful installation, check your updated version by opening a terminal and typing python3 –version. This should display the latest version.
2. Using Homebrew to Update Python
Homebrew is a popular package manager for MacOS that can simplify your Python upgrading process. Follow these steps to upgrade Python version using Homebrew:
- First, ensure that Homebrew is installed on your computer. If not, you can install it by following the instructions on the Homebrew website.
- Open a terminal window and update Homebrew by running the following command: brew update.
- Now, to install the latest version of Python, you can run: brew install python. This command will download and install the most recent Python version.
- If you have already installed Python using Homebrew, you can use the command brew upgrade python instead.
Once the installation is complete, check your updated Python version in the terminal by running python3 –version. Your system should now be running the latest version of Python.
By following either the Python.org Installer method or the Homebrew method, you can easily update your Python installation on MacOS.
How to Update Python on Linux
In this section, you’ll learn how to upgrade Python on Linux using the APT package manager.
The APT package manager is an essential tool for managing software on Ubuntu and other Debian-based distributions.
To upgrade Python using the APT repository, you can follow these steps:
- Open a terminal window.
- Update the package list by running the following command:
sudo apt-get update
- Upgrade Python by executing the following command:
sudo apt-get upgrade
This command will upgrade Python to the default version in your distribution’s package manager, which might be slightly behind the official release but is considered stable. - Verify the installation by running the following command:
python --version
This will display your existing version. If it has been successfully upgraded, it will show the new version.
By following the instructions in this section, you can successfully upgrade Python on your Linux system, ensuring you have the latest features, security patches, bug fixes, and tools available for your projects.
Final Thoughts
Updating Python is an essential step in keeping your development environment safe and efficient. By doing so, you’re ensuring access to the latest features and improvements.
When you upgrade Python, you benefit from the efforts of the Python community to make the language better, more secure, and more capable.
The newer versions of Python can give you faster execution, better memory management, and access to new libraries or functions. Every update to Python empowers you to write cleaner and more efficient code.
Whether you’re using Windows, macOS, or Linux, following the right steps will ensure a smooth transition to the newer version!
Frequently Asked Questions
In this section, we’ve listed some frequently asked questions when updating Python to the latest version. Give it a look as these questions may be helpful in some of the confusion you might have.
How to upgrade Python on Windows?
To upgrade Python on Windows, visit the Python official website and download the installer for the version you want to update to.
Run the installer and follow the on-screen instructions. Remember to tick the “Add Python to PATH” option during the installation.
Can I update Python using pip?
No, you can’t update Python itself using pip. Pip is a popular Python package manager; it’s used to install and manage software packages/libraries written in Python, not to upgrade the Python interpreter itself.
How to update Python with conda?
To upgrade your Python version with conda, open your terminal or command prompt and enter the following command:
conda update python
This will upgrade your Python version to the latest one available in your conda environment.
How can I switch from Python 2.7 to 3.6 on Linux?
To switch from Python 2.7 to 3.6 on Linux, you can use the following commands:
sudo apt update
sudo apt install python3.6
My Python Version is not updating, what should I do?
If your Python versions are not updating, double-check that you have installed the new version correctly and that your system PATH includes the updated version. You can also try uninstalling the old version of Python before installing the new one.
To learn more about handling errors in Python, check the following video out: