Methods to Update Python in Windows
- Update Python in Windows Using the Python Windows Installer
- Update Python in Windows Using Chocolatey
In this tutorial, we will look into different ways to update Python in Windows 10. We will discuss how to upgrade the Python version from 3.x to 3.y and how to install the latest version of Python 3 or Python 2.
Update Python in Windows Using the Python Windows Installer
One simple way to update the Python in Windows is to download the required version of the Python on your computer from Python Download Page for Windows.
Once the installation file is downloaded, after opening or running the setup, the Upgrade Now
option will appear if version 2.xy or 3.xy is already installed on the computer and an update to version 3.xz or 2.xz is available. In this case, the existing version of Python will be replaced by the newly installed version.
In case the currently installed version of Python in the computer is 2.x or 3.x, and the installation file of some newer version like 2.y or 3.y is downloaded, the newer version will be installed as a separate version on the computer and the older version will not be replaced or deleted.
Now after installation, multiple versions of Python will be available on the computer. Therefore, to use the specific version of Python, we can use the following command on Command Prompt or Windows PowerShell:
To use some specific installed version of Python 2:
py -2.xy
To use some specific installed version of Python 3:
py -3.xy
Update Python in Windows Using Chocolatey
Chocolatey is a command-line tool that is used to manage software packages on Windows. It allows the user to version software, manages dependencies and requirements to install and upgrade different software. In case Chocolatey is not installed, the setup can be downloaded and installed by following the instructions available on this link.
Once Chocolatey is installed, we can easily install or update Python on our computer using the following commands on Command Prompt or Windows PowerShell as administrator:
Install Python 3.x:
choco install python3 --pre
Update Python 3.x:
choco upgrade python3 --pre
Install Python 2.x:
choco install python2
Update Python 2.x:
choco upgrade python2
Now suppose we want to execute the Python script using some specific version of Python. Before executing the script, we will first specify the Python version that is already installed on the computer. We can do so by specifying the Python version on the first line of the Python script file.
We can use the following text as the first line of the script file if we want to use the latest version of Python 3 available on the computer to execute the Python script:
#! python3
We can also specify the Python version of our choice by putting the following text as the first line in the Python script file:
#! python 2.5