List of content you will read in this article:
Python doesn’t come pre-installed in Windows. However, it’s not that difficult to install Python on Windows systems and start creating Python programs. Through this article, we will guide you with all the essential information along with the steps that you need to install and run Python in Windows. But before that, let’s take a quick look at Python itself.
Python is a popular high-level programming language that is used extensively in software development as well as web development. It has always been a favorite of hobbyists and qualified developers alike, owing to a design concept that stresses readability. Python is also one of the easiest programming languages to learn and understand, which accounts for its ever-growing popularity.
What Version of Python Would Users Require?
Regrettably, a major upgrade to Python many years ago resulted in a large break among Python releases. This may be a little perplexing for beginners, but don't worry, we'll demonstrate how to set up all the major Python versions on Windows.
When you visit Python's official website and navigate to the Python for Windows downloads tab, you'll notice a large number of Python versions that are available for download. The registry always asks whether you want to upgrade to the latest version of Python 2 or Python 3.
We recommend running both the version, Python 2 and Python 3 at the same time if you want to get the most out of Python. This helps you to use the latest Python version while still operating older Python scripts and testing the functionality of projects that have been developed using a newer version of Python.
If you're certain that you only need one version of Python, you may install just Python 2 or Python 3 as per your requirements. However, we're going the extra mile to show you the installation of each one of these. We suggest you follow the steps closely to be able to install Python on your Windows system successfully. First, install the "x86-64" installer of a particular Python version, which is highlighted in the image as shown below:
Python 2 Installation Instructions
Python 2 is easy to update, and unlike previous versions, the installer will also set the path variable for you (which we'll discuss later).
- Download and run the installer, then press "Next" after selecting the option "Install for all users."
- Leave the folder as "Python27" and press "Next" on the Select Destination Directory page.
- Scroll down to “Add python.exe to Path,” then select “Will be installed on local hard drive” on the customization screen. Click on the"Next" button once you're done.
Now, you won't have to make any more choices. To complete the installation, simply follow the wizard's instructions. When the installation is complete, open Command Prompt and type the following command to validate the installation:
You should stop yourself right here if all you need is Python 2.7 to work on your project. It is installed successfully on your Windows system and the path variable has been configured, so you’re ready to use Python.
Python 3 Installation Instructions
Python 3 must be installed if you wish to work with the most recent version of Python. It'll fit well with Python 2.7, so go ahead and install it on your system.
- After downloading the installer of the latest Python 3 versions (which is Python 3.6 at the time of writing), launch the installer. Activate the “Add Python 3.6 to PATH” choice on the first page, then press “Install Now.”
- After that, you must make a choice. The MAX PATH variable is no longer limited when you choose the “Disable path length limit” option. This update will not cause any problems, but it will enable Python to use long path descriptions. Because many Python programmers operate on Linux and other *nix systems where path description width isn't really an issue, switching this on ahead of time will help you avoid any path-related problems you may encounter when operating in Windows.
We suggest that you choose that alternative. If you are certain that you do not wish to disable the path length restriction, simply press "Close" to complete the installation.
If you're just installing Python 3, type python -v to see if it's loaded correctly and the path variable is set. However, if you're downloading both a Python 2 and Python 3 version, make a simple tweak that is described in the upcoming section.
Change Default Settings to Provide Command-Line Access to All Python Versions
This section is entirely optional, but it will allow you to easily switch between different Python versions from the command-line interface (CLI). Despite the fact that both Python installations have the system path available, typing "python -v" at the command prompt only returns Python 2.7.
The explanation for this is simple; the vector merely points to a folder, and any executable in that directory becomes a command-line command (whether automatically changed by an installer or manually tweaked). If two files are specified with a “python.exe” file in each, the folder that is the highest in the list of variables will be used. The machine path takes precedence over the user path when both process and the operator have parameters configured.
This is precisely what is happening throughout this scenario: the Python 2 installer changed a system-wide variable, while the Python 3 installer introduced a user-level variable, as we can see from the Windows environment variables.
Select the “View advanced system settings” option from the Start menu after typing “advanced system settings” into the search box. On the "Advanced" tab of the "System Properties" window that appears, press the "Environment Variables" button.
In the “User variables” column, Python 3 is listed, while Python 2 is listed in the “System variables” section.
There are a few options for dealing with this. The easiest solution is to simply delete the entry for the Python version you want to use the least. Although this is straightforward, it isn't particularly enjoyable. Instead, we should make a different modification that allows us to use Python 2 as “python” and Python 3 as “python3”.
To do so, open File Manager and navigate to the Python 3 installation folder (C:\Users\[username]\AppData\Local\Programs\Python\Python36 by default). Make a duplicate of the “python.exe” file, and rename that duplicate to “python3.exe”.
Create a new command prompt on your device. Your environmental variables are refreshed when you open a new command prompt window and type. “
It's a bang! When you want to use Python 2.7, you can always use the “python” command at the cmd, and when you want to use Python 3, use the “python3” command.
Python is a popular high-level programming language used for software and web development. We have seen how to install Python 2 and Python 3 conveniently. We can also run both versions of Python simultaneously to convert our Python 2 files into Python 3 and vice-versa. Leave your feedback for suggestions or queries in the comments below. Also, if you wish to install Python on Ubuntu instead, please check out this detailed tutorial.