Your next chapter / Run your first Python program

Foundation · 35 MINUTES · VERSION 1

Run your first Python program

Run your first Python file on Windows or Ubuntu/Linux, understand terminal differences, and create an isolated project environment.

Reviewed 23 Oct 2026

Your setup may differ. Windows, Ubuntu, and optional tool bundles →

Log in or create an account to keep private notes, bookmarks, and learning progress. Reading is free without an account.

What you will learn

  • Find the Python interpreter on your computer.
  • Create a small program and run it from a terminal.
  • Choose the correct command for Windows or Ubuntu/Linux.

The idea in simple English

Python is a programming language. An interpreter is the program that reads and runs Python code. A file ending in .py contains Python source code. A terminal lets you give commands to your computer.

You can learn Python on Windows, Ubuntu/Linux, or macOS. You do not need a PHP server bundle for these exercises. Laragon and XAMPP are optional tools used by some web developers; they are not course requirements. This lesson uses only Python and a text editor. Run exercises on your own computer. The website does not run uploaded code.

Step 1: check your interpreter

Choose the command for your operating system. On Windows, open PowerShell, Command Prompt, or Windows Terminal:

python --version

If that command is not available, try py --version. The exact command depends on your Python installation. If you need Python, use the official Python download/setup instructions linked below. Close and reopen the terminal after installation.

On Ubuntu/Linux, open Terminal:

python3 --version

Expect a line beginning with Python 3. followed by a version number. Use a supported release. These examples were tested with Python 3.13; they do not require that exact patch version.

A missing command can mean the interpreter is not installed, the terminal is using a different environment, or its folder is not on PATH. PATH is the list of folders searched for command names. On Windows, Get-Command python in PowerShell or where python in Command Prompt helps identify the command. On Ubuntu, use command -v python3.

If Ubuntu needs the full development environment, follow the linked Ubuntu guide for its python3-full package. Do not replace or remove Ubuntu's system Python. Use virtual environments for project packages.

If you use Laragon, XAMPP, another bundle, or a custom editor, check whether Python is actually included and available in that terminal. Having PHP installed does not prove Python is installed. A bundle is optional: the interpreter and its version are what matter.

Step 2: create a practice folder

Use a new folder such as python-practice, outside any real company project. Open it in your editor and terminal. Create hello.py:

name = "Developer"
print(f"Hello, {name}!")
print("I am learning one step at a time.")

name is a variable: a name attached to a value. print writes text to the terminal. The f before a quoted string lets Python insert a value inside {}.

Run it with your working interpreter. Choose one row:

Environment Run the file
Windows with python available python hello.py
Windows using py py hello.py
Ubuntu/Linux python3 hello.py
macOS with Python 3 installed Use your installed command, commonly python3 hello.py

The Python code is the same. Only the launch command differs. If you use a full interpreter path in PowerShell, put & before a quoted executable path. Run the command from the folder containing hello.py.

Expected output:

Hello, Developer!
I am learning one step at a time.

Step 3: keep project packages separate

A virtual environment is a separate Python environment for one project. It helps projects use different packages without changing each other.

Windows — if your working command is python:

python -m venv .venv
.\.venv\Scripts\python.exe hello.py
.\.venv\Scripts\python.exe -m pip --version

If you use the Windows py command, create the environment with py -m venv .venv, then use the same .venv\Scripts\python.exe commands above. In Command Prompt, omit the leading .\ if needed.

Ubuntu/Linux:

python3 -m venv .venv
./.venv/bin/python hello.py
./.venv/bin/python -m pip --version

If Ubuntu reports that venv is unavailable, use the official Ubuntu guide to install its virtual-environment support (python3-full includes it). Do not install course packages globally into the system interpreter.

These commands use the environment's interpreter directly, so activation is not necessary. On Windows you do not need to change PowerShell execution policy. macOS environments use the bin/python layout too. Do not copy a virtual environment between operating systems; create it again on the new computer. No external package is needed for this lesson. Do not commit .venv to Git.

Guided practice

  1. Check the interpreter version.
  2. Run the unchanged example and compare both output lines.
  3. Change the name to your own first name and run it again.
  4. Run the same file using your virtual environment's interpreter.

Independent exercise

Add a variable called topic with the value Python. Print a third line: Today I will practise Python. Use the variable in an f-string. Try changing the topic to SQL. Reveal the hints only after trying.

Common mistakes

  • python is not recognized: check the interpreter location and PATH. Do not reinstall tools without checking first.
  • can't open file: the terminal is in a different folder, or the filename is wrong.
  • SyntaxError: check quotation marks, parentheses, and spelling. Read the line number in the error.
  • A .py.txt filename: enable filename extensions in your editor or file manager.

Self-check — not graded

  1. Must you install Laragon or XAMPP to run this Python exercise?
  2. What runs a .py file?
  3. Why use a virtual environment?

Interview practice

“How do you keep Python dependencies separate for two projects?” Explain that each project can have its own virtual environment and dependency list. The environment is recreated from the project's instructions, rather than copied between computers.

English practice and glossary

  • Interpreter: the program that executes your Python code.
  • Terminal: a place to enter commands and read their output.
  • PATH: folders searched when you type a command name.
  • Virtual environment: an isolated environment for one Python project.

Say: “I checked my Python version. I created a program. I ran it from the terminal.” Write one sentence explaining an error you met and how you fixed it.

Next step

Keep this practice folder. Next, learn values, types, and calculations. You do not need AI packages yet.

Reveal exercise hints and self-check answers

Exercise hint: add topic = "Python", followed by print(f"Today I will practise {topic}."). Changing the variable changes the inserted word.

  1. No. You need Python and an editor. A PHP server bundle is optional and unrelated to this exercise.
  2. The Python interpreter executes the file.
  3. It separates a project's package environment from other projects.

Official references

Practise on your own computer. The exercise self-checks are not graded. This version has no scored quiz. Signed-in learners can save reading, self-reported practice, private notes, and bookmarks.