Contents
Open the terminal by searching for it in the dashboard or pressing Ctrl + Alt + T . Navigate the terminal to the directory where the script is located using the cd command. Type python SCRIPTNAME.py in the terminal to execute the script.
How do I run a Python file in Ubuntu terminal?
Option 2: Let the script call the interpreter
- Make sure the first line of your file has #!/usr/bin/env python .
- Make it executable – chmod +x <filename>. py .
- And run it as ./<filename>.py.
How do I run a .PY file in Terminal?
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!