Skip to content
Home » Blog » How to Install Python and Run Your First Program in Just 5 Minutes

How to Install Python and Run Your First Program in Just 5 Minutes

How to Install Python and Run Your First Program in Just 5 Minutes

Introduction

Python is one of the most beginner-friendly programming languages, and that’s a big reason why it’s so popular. Whether you’re interested in web development, data science, automation, or AI, Python is a great place to start. It has a simple syntax, a massive community, and works on almost any operating system. In this guide, you’ll learn how to install Python and run your first Python script in just a few minutes. Let’s get started!

Step 1: Download and Install Python

Check if Python is Already Installed

Before installing Python, let’s check if it’s already on your system. Open your terminal (Mac/Linux) or command prompt (Windows) and type:

python --version

or

python3 --version

If Python is installed, you’ll see an output like this:

Python 3.x.x

If you get an error or no version is displayed, that means Python isn’t installed, and you’ll need to install it manually. Let’s do that next!

Download Python from the Official Website

A structured flowchart visualizing the Python installation process, with text boxes representing each step, such as checking installation, downloading Python, selecting OS, verifying installation, and running Python. Arrows indicate the flow of the process.
Python Installation Process Flowchart – A step-by-step guide to setting up Python on different operating systems.

To install Python, you’ll need to download the latest version from the official Python website:

🔗 Download Python

Let’s go through the process step by step for Windows, macOS, and Linux.

Windows Users

  1. Visit the Python Download Page: Go to python.org/downloads and click the big yellow “Download Python 3.x.x” button.
  2. Run the Installer: Locate the downloaded file (usually in the “Downloads” folder) and double-click it to open.
  3. Enable “Add Python to PATH”: Before clicking “Install Now,” check the box that says “Add Python to PATH.” This is important because it allows you to run Python from the command prompt without extra configuration.
  4. Start Installation: Click “Install Now”, and wait for the installation to complete.
  5. Verify Installation: Open Command Prompt (Win + R, type cmd, and press Enter), then type: bashCopyEdit
python --version

If Python is installed correctly, you’ll see an output like:

Python 3.x.x

macOS Users

  1. Download Python: Visit python.org/downloads and download the macOS installer (.pkg file).
  2. Open the Installer: Locate the downloaded file (usually in the “Downloads” folder) and double-click it to open the installation wizard.
  3. Follow Installation Steps: Click “Continue” and follow the on-screen instructions.
  4. Verify Installation: Open Terminal (Cmd + Space, type Terminal, and press Enter), then run:
python3 --version

If Python is installed correctly, you should see:

Python 3.x.x

Linux Users

Most Linux distributions come with Python pre-installed. But if you need to install or update it, follow these steps:

  1. Check if Python is Installed:
    Open a terminal and type:
python3 --version

If you see something like Python 3.x.x, you’re good to go! If not, install it using the following commands based on your Linux distribution:

2. Install Python on Ubuntu/Debian:

sudo apt update && sudo apt install python3

3. Install Python on Fedora:

sudo dnf install python3

4. Install Python on Arch Linux:

sudo pacman -S python

5. Verify Installation: After installation, run:

python3 --version

You should see:

Python 3.x.x

Now that Python is installed, let’s move on to running your first Python program!

Step 3: Run Your First Python Program

A structured flowchart illustrating two methods for running a Python program: using the interactive shell and executing a script. Each step is represented with labeled text boxes and arrows showing the process flow.
Running Your First Python Program: Command Line vs. Script Execution – A step-by-step visual guide for executing Python code using the interactive shell and script execution methods.

Now that Python is installed, let’s write and run your first program! There are two main ways to run Python code:

  1. Using the Python Interactive Shell (for quick testing)
  2. Writing a Python Script (for saving and running later)

Using the Python Interactive Shell

The Python Interactive Shell (also called the REPL) lets you run Python commands one at a time. This is great for quick tests and debugging.

Steps to Open the Python Shell:

  1. Open Command Prompt (Windows) or Terminal (Mac/Linux).
  2. Type:
python

(If this doesn’t work, try python3 instead.)

3. You should see something like this:

Python 3.x.x (default, YYYY-MM-DD)  
Type "help", "copyright", "credits" or "license" for more information.
>>>  

4. Now, type this simple command and press Enter:

print("Hello, Python!")

5. You should see the output:

Hello, Python!

6. To exit the shell, type:

exit()

or press Ctrl + Z (Windows) / Ctrl + D (Mac/Linux).

Writing a Python Script (.py File)

If you want to save your code and run it later, you need to write a Python script (a .py file).

Steps to Create and Run a Python Script:

  1. Open a Text Editor
    You can use any text editor, such as:
    • VS Code (Recommended)
    • Notepad++
    • Nano (Linux)
    • Built-in Notepad (Windows)
  2. Write Your First Python Program
    Type the following code:
print("Welcome to Python programming!")

3. Save the File

  • Click File > Save As…
  • Name the file first_program.py
  • Make sure to save it in a folder where you can easily find it.

4. Run the Script

  • Open Command Prompt (Windows) or Terminal (Mac/Linux).
  • Navigate to the folder where you saved the file using cd:
cd path/to/your/file

(For example, if your file is in Documents/Python, use cd Documents/Python.)

Run the script with:

python first_program.py

(If this doesn’t work, try python3 first_program.py.)

5. See the Output!
You should see:

Welcome to Python programming!

Must Read


Step 4: Set Up a Python IDE (Optional but Recommended)

While you can write and run Python programs using a basic text editor and terminal, using an IDE (Integrated Development Environment) makes coding easier. An IDE provides syntax highlighting, auto-completion, debugging tools, and better organization.

Best Python IDEs for Beginners

Here are three great options for beginners:

IDLE (Built-in Python IDE)

  • Comes pre-installed with Python.
  • Simple and easy to use for small scripts.
  • To open it, just type idle in the command prompt (Windows) or terminal (Mac/Linux).
  • Best for learning and quick testing, but lacks advanced features.

VS Code (Recommended for Beginners & Pros)

PyCharm Community Edition (For Serious Python Development)

  • Designed specifically for Python.
  • Great for large projects and debugging.
  • To install:
    1. Download PyCharm Community Edition (free) from JetBrains’ website.
    2. Install and open PyCharm, then create a new Python project.

Running Python Programs in an IDE

Running Python in VS Code

  1. Open VS Code and install the Python extension (if not already installed).
  2. Open your Python script:
    • Click File > Open Folder and select the folder where your .py file is saved.
    • Click on the .py file to open it in VS Code.
  3. Run the script:
    • Click the Run button (▶️ at the top right) OR
    • Press Ctrl + Shift + P and type Run Python File in Terminal.
    • You’ll see the output in the Terminal window below.

Running Python in PyCharm

  1. Open PyCharm and create a new project.
  2. Open your Python script:
    • Click File > Open and select your .py file.
  3. Run the script:
    • Click Run > Run… and select your script OR
    • Press Shift + F10.
    • The output will appear in the Run window at the bottom.

Why Use an IDE?

Using an IDE makes writing, debugging, and running Python code much easier. If you’re serious about learning Python, setting up an IDE is a great step!

Step 5: Troubleshooting Common Installation Issues

A flowchart illustrating how to fix the "Python is not recognized as an internal or external command" error. It outlines troubleshooting steps for Windows and macOS/Linux, showing how to add Python to the system PATH and verify the installation.
Fixing the “Python Not Recognized” error: A step-by-step troubleshooting guide for Windows and macOS/Linux users.

Sometimes, after installing Python, you might run into issues when trying to use it. Here’s how to fix some of the most common problems.

Python Not Recognized in Command Line

If you see an error like this when running python in the command prompt (Windows) or terminal (Mac/Linux):

'python' is not recognized as an internal or external command, operable program, or batch file.

or

command not found: python

it means Python isn’t added to your system’s PATH. Here’s how to fix it:

🛠 Fix on Windows:

  1. Check if Python is Installed Correctly
    • Open Command Prompt (Win + R, type cmd, and press Enter).
    • Type:
where python
  • If Python is installed but not found in the PATH, you’ll need to manually add it.

Add Python to PATH (Windows 10/11)

  • Open Settings > System > About.
  • Click Advanced system settings on the right.
  • Click Environment Variables.
  • Under System Variables, find and select Path, then click Edit.
  • Click New, then add the path to your Python installation (e.g., C:\Python39\ or C:\Users\YourUsername\AppData\Local\Programs\Python\Python39\).
  • Click OK and restart your computer.

Check if Python Works

  • Open Command Prompt again and type:
python --version

You should see something like:

Python 3.x.x

Fix on macOS/Linux:

  1. Check if Python is Installed
    • Open Terminal and type:
which python

If nothing appears, try:

which python3

2. Use python3 Instead

  • On macOS and some Linux systems, Python 2 and Python 3 are both installed.
  • Always use:
python3 --version
  • If Python 3 is installed but python still runs Python 2, you can set python to use Python 3:
alias python=python3

Running Python 2 Instead of Python 3

On some older systems, running python might start Python 2, which is outdated.

🛠 Fix on Windows:

  • Use python --version to check which version is running.
  • If Python 2 appears, try running python3 instead:
python3 --version

If that works, you can update your system to use python instead of python3:

  • Open Command Prompt as Administrator.
  • Type:
py -3
  • If Python 3 runs, update your system’s PATH (see Step 5.1).

🛠 Fix on macOS/Linux:

  • Always use python3 instead of python.
  • If you want python to default to Python 3, set an alias:
alias python=python3
  • To make it permanent, add this line to your ~/.bashrc or ~/.zshrc file:
echo "alias python=python3" >> ~/.bashrc

Then restart your terminal.

Final Check: Confirm Python Installation

Once you’ve fixed the issues, run:

python --version

or

python3 --version

If you see Python 3.x.x, you’re good to go!

Conclusion

You’ve successfully installed Python and run your first script! 🎉 Let’s quickly recap what we covered:

  • Checked if Python is installed on your system.
  • Downloaded and installed Python from the official website.
  • Ran Python in the interactive shell and wrote your first script.
  • Set up an optional IDE for better coding experience.
  • Troubleshot common issues like PATH errors and Python version conflicts.

This is just the beginning of your Python journey! Now that you have Python up and running, here are some great next steps:

Learn Python basics: Explore concepts like variables, loops, functions, and lists.
Write more Python scripts: Automate tasks, build small programs, and get hands-on practice.
Explore Python frameworks: Start with Flask for web development, Pandas for data analysis, or TensorFlow for AI.

Ready to take the next step? Check out our guide on Python Basics for Beginners to continue your learning!

FAQs

1. How can I check if Python is already installed on my computer?

Open the Command Prompt (on Windows) or Terminal (on macOS/Linux) and type “python” or “python3.” If Python is installed, it will display the version number.

2. Which Python version should I install?

Always install the latest stable version of Python 3 from the official Python website. Python 2 is outdated and no longer supported.

3. How do I run a Python script after installation?

Save your script with a .py extension, then open the Command Prompt or Terminal, navigate to the file location, and run the script by typing “python” followed by the filename.

4. Why does my system say Python is not recognized?

This happens when Python is not added to the system PATH. You can fix it by reinstalling Python and selecting the “Add Python to PATH” option during installation, or by manually updating your system’s environment variables.

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *