Option 1: Call the interpreter

  • For Python 2: python <filename>.py
  • For Python 3: python3 <filename>.py

Option 2: Let the script call the interpreter

  1. Make sure the first line of your file has #!/usr/bin/env python.
  2. Make it executable - chmod +x <filename>.py.
  3. And run it as ./<filename>.py
Answer from abhshkdz on askubuntu.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › open-and-run-python-files-in-the-terminal
Open and Run Python Files in the Terminal - GeeksforGeeks
July 23, 2025 - In this article, we'll explore various techniques and commands for handling Python files in the Linux terminal, empowering developers to streamline their workflow and enhance productivity. ... 2. Use the cd command to change the present working directory to the directory in which the Python program file is saved or in which you want to create the program file.
Discussions

How to execute python file in linux - Stack Overflow
Using linux mint, to run a python file I have to type python [file path] in the terminal. Is there a way to make the file executable, and make it run the python command automatically when I double-... More on stackoverflow.com
🌐 stackoverflow.com
How to execute a python script?
Please Re-Flair your post if a solution is found. How to Flair a post? This allows other users to search for common issues with the SOLVED flair as a filter, leading to those issues being resolved very fast. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/linuxmint
16
15
August 17, 2021
what is the simplest way to run a a python script?
I would be very careful before letting code, produced by Chatgpt, play with my file system. More on reddit.com
🌐 r/learnpython
19
7
February 13, 2023
Running Python Programs from a Terminal
Well what are you trying? What command exactly? Can you show us the complete error you are getting? Also, what OS are you using and how did you install python? More on reddit.com
🌐 r/learnpython
16
1
August 2, 2022
🌐
DigitalOcean
digitalocean.com › community › tutorials › run-python-script-on-ubuntu
How to Run a Python Script on Ubuntu | DigitalOcean
July 15, 2025 - The most direct way to run a Python script on Ubuntu is by using the python3 your_script.py command in your terminal. Always use a virtual environment (venv) to isolate project dependencies and avoid conflicts with the system’s Python packages. You can make a script run like a native command ...
🌐
Educative
educative.io › answers › how-to-run-a-python-script-in-linux
How to run a Python script in Linux
For this tutorial, we shall place it on the desktop. Now, open the terminal, for most Linux flavors using the shortcut "Ctrl + Alt + T" should work. In case it doesn't, we can type it in the search bar and open the terminal from there.
🌐
Digis
digiscorp.com › how-to-run-python-file-in-terminal
How to Run Python File in Terminal? - Digis
July 29, 2025 - Learn how to run a Python file in the terminal with this step-by-step guide. From setup to troubleshooting, discover tips for running Python scripts efficiently. Perfect for beginners and developers!
🌐
Oxylabs
oxylabs.io › blog › how-to-run-a-python-script-in-terminal
How To Run A Python Script In Terminal
On Linux, search for the Terminal or its synonyms (cmd, command prompt, shell) in the Activities window or by pressing the Show Apps button. This process may be different depending on your Linux distribution and its version.
Find elsewhere
🌐
FavTutor
favtutor.com › blogs › run-python-file-terminal
How to Run a Python File in Terminal? (Step-by-Step)
November 14, 2023 - On macOS or Linux, you can open the terminal by searching “Terminal” in Spotlight or in the applications menu. Navigate to Directory: Once the terminal or the command prompt is open, the next step is to navigate to the directory of the python file. You can do that with the command ‘cd’ followed by the file directory. If the path of the file directory is “C:/User/Documents/PythonPrograms”, you can enter cd C:/User/Documents/PythonPrograms. Run File in Folder: Now you have to run the python file in the folder.
🌐
Linux Handbook
linuxhandbook.com › run-python
How to Run Python Scripts in Linux Command Line
September 28, 2023 - To make your Python script executable, run the following command in your terminal: ... This should be it. Right? I have a file hello.py, let's try running it. $ cat hello.py print("Hello Linux Handbook!") $ chmod +x hello.py $ ./hello.py ./hello.py: 1: Syntax error: word unexpected (expecting ")")
🌐
Scaler
scaler.com › home › topics › how to run python script in linux?
How To Run Python Script in Linux? - Scaler Topics
June 5, 2024 - For example, if your script is ... you can run it using the Python interpreter. In the Terminal, type python3 followed by the name of your script and press Enter....
🌐
LearnPython.com
learnpython.com › blog › open-python-files-in-terminal
How to Open and Run Python Files in the Terminal | LearnPython.com
A Python file or script is written in the Python language and saved with a ".py" extension. In this article, we focus on how to interact with Python files. We will learn how to create and open Python files in the terminal. We will also demonstrate how to run Python files in the terminal and redirect the output of the script to a file.
🌐
Real Python
realpython.com › run-python-scripts
How to Run Your Python Scripts and Code – Real Python
February 25, 2026 - The python command’s -m option runs Python modules by searching sys.path rather than requiring file paths. IDEs like PyCharm and code editors like Visual Studio Code provide built-in options to run scripts from the environment interface. To get the most out of this tutorial, you should know the basics of working with your operating system’s terminal and file manager.
🌐
vteams
vteams.com › blog › how-to-run-a-python-script-in-terminal
How to Run a Python Script in Terminal Step by Step Guide
April 7, 2025 - To execute a Python script, first open a terminal, then navigate to the directory where the script is located, and finally, run the script using the ‘python’ command followed by the script’s name. On Linux, consider using python3 to ensure you’re using Python 3. On Windows, make Python scripts executable using batch files ...
🌐
Linuxize
linuxize.com › home › python › how to run a python script in linux
How to Run a Python Script in Linux | Linuxize
April 17, 2026 - When you have a Python script ready on a Linux system, the next step is usually straightforward: run it from the terminal. Most of the time you will use python3 script.py, but it also helps to know how to make the file executable, pass arguments, and run modules with -m.
🌐
Pluralsight
pluralsight.com › blog › software development
Introduction to Python in Ubuntu Linux | Pluralsight
March 12, 2025 - To run a script from the command line, type: python my_script.py. To exit the command line, type exit() or hit ctrl+d. Can't imagine writing a long program from the command line? Me either.
🌐
JC Chouinard
jcchouinard.com › accueil › how to create and run a python script with terminal (command line example)
How to Create and Run a Python Script with Terminal (Command Line Example) - JC Chouinard
April 4, 2025 - Press esc to leave the editing mode. Write the command :wq to save and quite the vim editor (w for write and q for quit). Run your script by typing python hello.py in the Terminal.
🌐
OpenPython
openpython.org › home › articles › how to run a python file (.py): windows, mac, and linux
How to Run a Python File (.py): Windows, Mac, and Linux | OpenPython
2 days ago - Both problems have clear fixes covered below. The standard command is python3 filename.py from your terminal (or python on Windows) On Mac and Linux, always use python3 — the python command often runs Python 2
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › how to run a python script
How to Run a Python Script: Beginner's Complete Guide
March 28, 2026 - ... On macOS, open Terminal and run the script with python3 script.py. This is the most reliable command on modern Mac systems because python3 clearly points to Python 3, which helps avoid confusion when learning how to start a Python script.