Installing Python
Table of Contents
In the last lesson, we learned why Python is useful. Now let’s install Python so we can run our own programs.
Before We Start
Okay, so we are convinced. We want to learn Python. Good.
But before we can write any code, we need Python on our computer. Think of it like this. We want to write a letter. We need a pen and paper first, right? Same thing. Python is our pen. But first we need to bring it home.
Let’s do this together. Step by step.
Step 1: Check If Python Is Already Installed
Sometimes Python is already installed. Many computers come with it. Let’s check first.
Open our terminal or command prompt.
- On Windows: press the Windows key, type
cmd, and press Enter - On Mac: open
Terminalfrom our Applications folder - On Linux: open our terminal app
Now type this and press Enter:
python --versionIf Python is there, we will see something like:
Python 3.12.1That means we already have it. We can skip the installation part and jump to Step 6.
If we see an error like “command not found” or “not recognized,” then Python is not there. No problem. Let’s install it.
Step 2: Download Python from the Official Website
Open our browser. Go to this website:
python.orgThis is the official website. Always download from here. Do not download from random websites. The official one is safe.
Look for the Downloads section. We will see a big button that says “Download Python.” Click it. The website will figure out what kind of computer we have and give us the right file.
How to Install Python on Windows
Open the downloaded file.
Now listen carefully. This is important.
We will see a checkbox at the bottom of the installer window. It says:
“Add Python to PATH”
Check that box. Please. This is very important.
If we skip it, our computer will not know where Python is. And later when we try to run Python, it will say “I don’t know what that is.” Then we will have to reinstall everything. So just check the box now.
Then click “Install Now.”
Wait for it to finish. It takes a minute or two. When it is done, click Close.
How to Install Python on Mac
Open the downloaded file. A window will open. It looks like a package installer.
Click Continue. Click Continue again. Click Agree.
Click Install. It might ask for our password. Type it in. Wait for it to finish.
How to Install Python on Linux
Most Linux systems already have Python. But if we need to install it, open our terminal and type:
sudo apt updatesudo apt install python3That is for Ubuntu or Debian. Other Linux systems have their own commands. But honestly, if we are on Linux, we probably already know this stuff.
Step 6: Check That Python Is Installed Correctly
Now go back to our terminal or command prompt.
Type this again:
python --versionWe should see the version number. Like this:
Python 3.12.1If we see it, congratulations! Python is installed. We did it.
One small thing. On some computers, we might need to type python3 instead of python. Let’s try both if one does not work.
Step 7: Try the Python Shell (REPL)
This is the fun part. Let’s actually talk to Python.
Type this and press Enter:
pythonWe will see something like:
Python 3.12.1 (main, ...)Type "help", "copyright", "credits" or "license" for more information.>>>See that >>>? That is the Python prompt. It means Python is listening. It is waiting for us to say something.
Now type this:
>>> print("Hello")Press Enter.
We will see:
HelloLook at that. We just ran our first Python code. Right now. Just like that.
To exit, type:
>>> exit()Or press Ctrl + Z then Enter on Windows. Or Ctrl + D on Mac and Linux.
Installing Python: A Real-Life Example
Think of it like this. Installing Python is like installing a new app on our phone. We download it. We install it. Then we open it and start using it. The only difference is — this app lets us build other apps.
And that checkbox about “Add Python to PATH”? Think of it like giving our computer a map. Without the map, it cannot find Python. With the map, it always knows where to look.
Common Python Installation Problems and Fixes
Problem 1: “Python Is Not Recognized”
This means our computer cannot find Python.
On Windows, this usually means we forgot to check the “Add Python to PATH” box. So what do we do? We reinstall Python and check that box this time.
Or we try typing py instead of python:
py --versionThe py command often works even when python does not.
Problem 2: We See Python 2 Instead of Python 3
Some old computers have Python 2. We want Python 3. Always.
So what do we do? We try typing:
python3 --versionIf that shows Python 3, we use python3 instead of python from now on.
Problem 3: Nothing Happens When We Type Python
Let’s make sure we pressed Enter after typing. And let’s make sure there are no typos.
Next, we will learn about Running Python Programs so we can continue step by step.