Content · Programming · Python

Python Running .py Files from Command Prompt or Terminal

Running a .py file from a terminal is a reliable way to verify your Python program independently of any IDE. Learn the essential ideas and try a practical example.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Running a .py file from a terminal is a reliable way to verify your Python program independently of any IDE.

Understanding the Concept


Save a Python file in a known project directory. Open Command Prompt, PowerShell, or Terminal and navigate to that folder using cd. Run the file with your Python interpreter. Windows users with the Install Manager can use py -V:3.15 program.py; macOS/Linux users may use python3.15 program.py. The file path matters: if your current directory is different, provide the correct relative or absolute path. The output appears in that terminal.

When and Why You Would Use This


Once this works, you have two ways to execute your code: the IDE and the command line. Learning both makes future troubleshooting and automation easier.

Practical Example


py -V:3.15 hello.py
python3.15 hello.py

Understanding the Example


These are platform alternatives, not commands you must run together. The first targets the Windows Install Manager; the second targets a versioned interpreter on a Unix-like platform. The file must already exist.

Try It Yourself


Create a file with two print statements and run it once from PyCharm and once from a terminal.

Common Beginner Mistakes


  • Running a .py filename with no interpreter when file associations are not configured.
  • Using the wrong working directory and receiving a file-not-found message.
  • Assuming PyCharm is required to execute a Python script.

Key Takeaways


  • Use the terminal to run a saved Python source file.
  • Select Python explicitly when necessary.
  • A correct file path is as important as a working interpreter.
Share this resourceSend this page to someone who may find it useful.