Nearby lessons
2 of 108Python - Installation
Introduction
Before writing Python programs, you need to install Python on your computer.
Python installation is simple and takes only a few minutes.
In this chapter, you will learn how to download, install, and verify Python on Windows.
Before Installing Python
First check whether Python is already installed on your computer.
- Open the Command Prompt.
- Type the following command:
pythonIf Python is already installed, Python starts or its version is displayed.
If you see a message like 'python' is not recognized as an internal or external command...,
it means Python is not installed on your computer.
Official Python Website
Always download Python from the official website.
Website:
This website is maintained by the Python Software Foundation.
From this website, you can:
- Download Python
- Read the official documentation
- Learn about Python
- Download the latest Python versions
Python Versions
When you visit the Python website, you will find different Python versions.
The two main versions are:
- Python 2
- Python 3
These are two different versions of Python.
Python 2 vs Python 3
Many beginners think Python 3 is just an updated version of Python 2.
This is not correct.
Python 3 was developed as a separate version.
- Python 2 and Python 3 are not fully compatible.
- A program written in Python 2 may not work correctly in Python 3.
- Most new features are available only in Python 3.
Which Version Should You Learn?
You should always learn and install the latest Python 3 version.
Reasons:
- Python 3 is the latest version.
- New features are added only in Python 3.
- Python 2 is no longer officially supported.
- Most companies use Python 3.
Python 2 support officially ended in 2020.
Therefore, beginners should always use Python 3.
Supported Operating Systems
Python is available for different operating systems.
- Windows
- macOS
- Linux
- Other platforms
In this tutorial, we will install Python on Windows.
Step 1 - Open the Official Python Website
Open your web browser.
Go to the official Python website:
This website is maintained by the Python Software Foundation.
Always download Python from this official website.
Step 2 - Open the Downloads Page
On the home page, you will see different menu options.
- Downloads
- Documentation
- Community
- About
Move the mouse over the Downloads menu.
The website automatically shows the latest Python version available for your operating system.
Step 3 - Select Your Operating System
Python is available for different operating systems.
- Windows
- macOS
- Linux
- Other Platforms
Choose the installer for your operating system.
In this tutorial, we are using the Windows version.
Step 4 - Download Python
Click the download button to start downloading Python.
The website downloads the latest stable version available.
The installer file is small, so the download usually finishes quickly.
Step 5 - Run the Python Installer
After downloading, open the Downloads folder.
Double-click the downloaded Python installer.
The Python Setup window will open.
Important Step - Add Python to PATH
Before clicking Install Now, look for the following checkbox:
Add Python to PATH
This is a very important step.
Always select this checkbox.
If you do not select it, Python commands may not work from the Command Prompt.
Step 6 - Install Python
After selecting Add Python to PATH, click Install Now.
The installer will automatically install the required components.
- Python Interpreter
- IDLE
- pip (Package Manager)
- Python Documentation
- Shortcuts
- File Associations
No manual configuration is required.
Step 7 - Installation Process
The installer copies all the required files to your computer.
Wait until the installation is completed.
After installation, you will see a success message similar to:
Setup was successful.Click Close to finish the installation.
Step 8 - Verify the Installation
After installing Python, check whether it is installed correctly.
- Open the Start Menu.
- Type Python.
You should see programs such as:
- Python 3.x
- IDLE
- Python Documentation
This confirms that Python has been installed successfully.
Verify Using Command Prompt
You can also verify the installation using the Command Prompt.
Open Command Prompt and type:
main.py
Python 3.x.x
Expected output:
Alternative Command
If the above command does not work, try:
main.py
Python 3.x.x
Expected output:
Installation Tips
- Always download Python from the official website.
- Always install the latest Python 3 version.
- Do not forget to select Add Python to PATH.
- Use Install Now unless you need a custom installation.
- Verify the installation after it is completed.
What is PATH?
After installing Python, one important thing is the PATH environment variable.
PATH tells Windows where installed programs are located.
When you type a command in the Command Prompt, Windows checks the folders listed in PATH to find the required program.
If Python is added to PATH, you can run Python from any folder without typing its installation location.
Why is PATH Required?
Suppose you open the Command Prompt and type:
pythonWindows searches for python.exe using the folders stored in the PATH environment variable.
How PATH Works
When you run a command, Windows follows these steps:
- Read the command you entered.
- Search every folder listed in the PATH environment variable.
- If the program is found, Windows starts it.
- If the program is not found, Windows shows an error message.
For the python command, Windows looks for the file python.exe.
If python.exe is available in one of the PATH folders, Python starts successfully.
What Happens if PATH is Not Set?
If Python is not added to PATH, Windows cannot find python.exe.
In that case, Python commands will not work from the Command Prompt.
You may see an error message similar to this:
'python' is not recognized as an internal or external command,
operable program or batch file.How Python Automatically Adds PATH
During installation, Python provides the option:
Add Python to PATH
If you select this option, the installer automatically adds the Python installation folder to the PATH environment variable.
You do not need to configure PATH manually.
This makes it easy to run Python commands from any folder.
Python vs Java PATH Setup
Many programming languages require manual PATH configuration.
For example, in Java, you usually need to set the JDK PATH manually.
In Python, this work is done automatically if you select Add Python to PATH during installation.
This makes Python installation easier for beginners.
Checking the PATH Environment Variable
You can check whether Python has been added to PATH.
- Open the Start Menu.
- Search for Environment Variables.
- Open Edit the system environment variables.
- Click Environment Variables.
- Select the Path variable.
- Click Edit.
If Python is installed correctly, you will see the Python installation folders listed in the PATH variable.
Benefits of Adding Python to PATH
- Run Python from any folder.
- No need to type the full installation path.
- Python commands work directly in the Command Prompt.
- Tools like pip also work easily.
- Python development becomes faster and easier.
Important Note
Always select Add Python to PATH during installation.
This saves time and avoids command errors in the future.