Have you ever written a Python program and then thought, “Now what?” Don’t worry! Running your Python file from the terminal is easier than making popcorn. Let’s walk through the steps together. We’ll keep it fun, light, and super beginner-friendly.
Table of Contents
Step 1: Make Sure Python is Installed
Before you run anything, you need to make sure Python is actually on your computer.
Open your terminal and type:
python --version
or try:
python3 --version
If you see something like Python 3.10.4, you’re golden! If not, you’ll need to install Python first. Go to the official Python website and follow the downloads section. It’s easy. Promise.

Step 2: Write a Simple Python File
Let’s write a simple Python file to test things out. You can use any text editor – Notepad, VS Code, Sublime Text, or even nano on the terminal if you’re feeling fancy.
Open your text editor and type the following:
print("Hello, world!")
Now save the file as hello.py.
- Make sure the file extension is .py.
- Save it somewhere easy to find.
- Remember the folder where you saved it!
Step 3: Open the Terminal
Time to get real. Open your terminal. The terminal is that black or white screen where you can type commands. Here’s how to access it on different systems:
- Windows: Search for Command Prompt or PowerShell
- macOS: Search for Terminal in Spotlight
- Linux: Press Ctrl + Alt + T or find Terminal in your system menu
Now you’re all set to command your computer like a boss.
Step 4: Navigate to the Python File
Let’s get to where your file lives using the cd command (which stands for change directory).
If your file is in the Documents folder, do this:
cd Documents
You can use the ls command to list the files in the current folder on macOS/Linux:
ls
Or dir on Windows:
dir
Make sure you can see your hello.py file there.
Step 5: Run the Python File
Alright, drumroll please… time for the magic. In the terminal, type this:
python hello.py
or, if you’re using Python 3 (which you probably are):
python3 hello.py
Hit Enter. If all goes well, you’ll see:
Hello, world!
Congrats! You just ran your first Python script from the terminal!

Extra Tips and Tricks
Running Python files is simple, but here are some bonus tips to level up your terminal game:
- Use the Up Arrow: Brings back your last command. Super handy!
- Clear the Screen: Type
clear
(on macOS/Linux) orcls
(on Windows) - Autocompletion: Type a bit of a folder or file name and hit
Tab
to autocomplete it - Use a Virtual Environment: For larger projects—keep your packages organized
What If Something Doesn’t Work?
No worries! Everybody hits a few bumps their first time.
- Error: ‘python’ is not recognized – You might need to add Python to your system’s PATH.
- Permission Denied – Check if you have permission to run files in that directory.
- Command Not Found – Try using
python3
instead ofpython
.
Still stuck? Just Google the error message. The internet is full of helpful coding wizards.
Running Files with Arguments
Python lets you pass arguments when you run your file. Here’s a quick example.
Create a file called greet.py with this code:
import sys
name = sys.argv[1]
print(f"Hello, {name}!")
Now run it like this from the terminal:
python greet.py Alice
Your output will be:
Hello, Alice!
That’s how you give values to your script from the outside. Pretty cool, right?
Using Python’s Interactive Mode
If you just want to try quick things out, type this in the terminal:
python
This opens the Python shell where you can type Python commands one at a time. Try:
>>> print("Hi there!")
To exit, type:
exit()
Think of this as your Python playground!
Creating a Standalone Program
Want to make your script clickable someday? Here’s a sneak peek.
- On Windows, you can rename
.py
files to.pyw
to run without showing the terminal. - On macOS and Linux, you can make the file executable like this:
chmod +x hello.py
Then run it using:
./hello.py
You’ll need to add a shebang line at the top of your file:
#!/usr/bin/env python3
That tells your system which interpreter to use.
Final Thoughts
Running Python files in the terminal opens a world of possibilities. It might feel weird at first, but trust us, it becomes second nature really fast.
- Write.
- Save.
- Run.
- Repeat.
That’s the coding life!
Now go ahead and write your own Python masterpiece. Your terminal is waiting!