PyLearn
PyLearn / Python Foundations / Installing Python
Lesson 02 · Foundations

Installing Python

Before you can write Python programs, you need a working Python environment. In this lesson, you will learn how to install Python, verify that it works, configure your development environment, and run your first Python file.

25–35 minutes Beginner Setup
Reading progress 0%

Learning objectives

By the end of this lesson, you should be able to:

  • Install Python on your operating system.
  • Check whether Python is installed correctly.
  • Understand the difference between Python and pip.
  • Configure Python in Visual Studio Code.
  • Create and execute a Python file.
  • Understand the purpose of PATH.
  • Recognize and solve common installation problems.
01

Before Installing Python

Python is available for the major desktop operating systems, including Windows, macOS and Linux. The installation process is slightly different on each operating system, but the goal is the same:

The goal of installation

You want your computer to be able to recognize the Python command from a terminal and execute Python programs.

What do you need?

  • A computer running Windows, macOS or Linux.
  • An internet connection for downloading Python.
  • A code editor such as Visual Studio Code.
  • Basic knowledge of opening a terminal.

You do not need an expensive computer to learn Python. Python is designed to run on a wide range of hardware.

02

Installing Python on Windows

Windows users can install Python using the official Python installer.

Step 1 — Download Python

Visit the official Python website and download the installer appropriate for your computer.

Step 2 — Start the installer

Open the downloaded installer. You will see an installation window with several options.

Important Windows setting

During installation, pay attention to the option that adds Python to your system PATH. Enabling this option makes it much easier to run Python from the terminal.

Step 3 — Complete installation

Continue through the installer and allow Python to finish installing.

Step 4 — Open Command Prompt

After installation, open Command Prompt or PowerShell and check the Python version.

python --version

If Python is installed and available through PATH, the terminal should display the installed Python version.

03

Installing Python on macOS

macOS includes some system software, but for learning modern Python development, it is better to install a current Python version explicitly.

Using the official installer

Download the appropriate Python installer for macOS and follow the installation instructions.

Verify the installation

Open Terminal and run:

python3 --version

On many macOS systems, the command python3 is used to explicitly refer to Python 3.

04

Installing Python on Linux

Many Linux distributions already include Python because various system tools depend on it.

However, the version available by default can vary between distributions.

Check Python first

python3 --version

If Python is not installed or the available version does not meet your project's requirements, use your Linux distribution's package manager or the official Python installation instructions.

Beginner tip

Do not remove or replace the Python installation that your operating system may use internally without understanding the consequences.

05

Verify That Python Is Installed

Installing Python is only the first step. You should always verify that your terminal can find and execute it.

Windows

python --version

macOS / Linux

python3 --version

You can also start the Python interpreter directly.

python

On systems where Python 3 is invoked with python3, use:

python3

You should see the Python interactive interpreter.

Example
Python 3.x.x
>>>

The exact version number will depend on the Python version installed on your computer.

06

Python vs pip

Beginners often confuse Python and pip. They are related, but they serve different purposes.

Tool Purpose
Python Runs Python programs.
pip Installs and manages Python packages.

Check pip

A common command is:

python -m pip --version

Using python -m pip helps make it clear which Python installation is being used to run pip.

What is a package?

A package is reusable Python software that can add functionality to your projects. We will study packages and pip in much greater detail later in the course.

07

Setting Up Python in Visual Studio Code

Visual Studio Code, commonly called VS Code, is a popular code editor for Python development.

Step 1 — Install VS Code

Download and install Visual Studio Code for your operating system.

Step 2 — Open VS Code

Launch VS Code after installation.

Step 3 — Install the Python extension

Open the Extensions panel and search for the official Python extension.

Install the Python extension and allow VS Code to activate Python development features.

Step 4 — Select the Python interpreter

VS Code may automatically detect your Python installation. If it does not, use the Python interpreter selection command and choose the Python installation you want your project to use.

Common beginner problem

Python can be installed correctly while VS Code is configured to use a different interpreter. Always check the selected interpreter when a program behaves unexpectedly.

08

Run Your First Python File

Now let's create an actual Python program.

Step 1 — Create a project folder

Create a folder somewhere convenient, for example:

PythonPractice

Step 2 — Open the folder in VS Code

Open the folder using VS Code.

Step 3 — Create a Python file

Create a new file called:

hello.py

Step 4 — Write Python code

print("Hello, Python!")

Step 5 — Run the program

Open the VS Code terminal and run:

python hello.py
Output
Hello, Python!
Congratulations!

You have just created and executed a Python program. From this point onward, your learning journey will focus on understanding what the code actually does.

09

Understanding PATH

PATH is an environment variable used by your operating system to locate executable programs.

When you type:

python --version

your operating system needs to know where the Python executable is located.

If the Python installation directory is available through PATH, the operating system can find Python without you typing its full file location.

What happens when PATH is missing?

You may see an error saying that Python is not recognized as a command, even though Python may actually be installed.

Don't panic

A PATH-related error does not necessarily mean that Python is completely missing. It can simply mean that your terminal cannot locate the Python executable.

10

Common Installation Problems

Problem 1 — Python command not recognized

If the terminal cannot find Python, first check that Python is actually installed. Then check whether the correct installation is available through PATH.

Problem 2 — Wrong Python version

Your computer may have more than one Python installation. Check which interpreter your terminal and VS Code are using.

Problem 3 — pip is not recognized

Instead of relying on a standalone pip command, try:

python -m pip --version

Problem 4 — VS Code runs the wrong interpreter

Open the Python interpreter selector in VS Code and choose the interpreter associated with your project.

Problem 5 — Terminal still shows old information

After changing installation or environment settings, close and reopen the terminal. In some cases, restarting VS Code or opening a new terminal session is necessary.

11

Practice: Set Up Your Python Environment

Now it is your turn. Complete the following tasks on your own computer.

Exercise 1

Check Python

Open your terminal and find out whether Python is installed.

python --version
Exercise 2

Check pip

Find the installed pip version.

python -m pip --version
Exercise 3

Create hello.py

Create a file named hello.py and write a program that prints your name.

For example:

print("My name is Adnan")
Challenge

Create a Python setup report

Find and record:

  • Your Python version
  • Your pip version
  • Your operating system
  • Your VS Code version

This simple habit will become useful when working with real-world Python projects.

12

Quick Knowledge Check

Test your understanding before moving to the next lesson.

1. What is the main purpose of Python?

2. What is pip mainly used for?

3. What does PATH help the operating system do?

4. Which file extension is commonly used for Python source files?

5. What should you check if VS Code is running the wrong Python environment?

13

Lesson Summary

You now understand the basic process of preparing a computer for Python development.

Python can be installed on Windows, macOS and Linux.
The terminal can be used to verify a Python installation.
Python runs Python programs.
pip is used to install and manage Python packages.
PATH helps the operating system locate executable programs.
VS Code can be configured as a Python development environment.
Python programs are commonly saved using the .py extension.
You are ready for the next step.

Your Python environment is now ready. In the next lesson, we will write and understand our first real Python programs.

Finished Lesson 02?

Mark this lesson complete when you have finished the reading, practice and quiz.