
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to Run a Python Program
There are three different ways to start Python −
Interactive Interpreter
You can start Python from Unix, DOS, or any other system that provides you a command-line interpreter or shell window.
Enter python the command line.
Start coding right away in the interactive interpreter.
$python # Unix/Linux or python% # Unix/Linux or C:> python # Windows/DOS
Here is the list of all the available command line options −
Sr.No. | Option & Description |
---|---|
1 | -d It provides debug output. |
2 | -O It generates optimized bytecode (resulting in .pyo files). |
3 | -S Do not run import site to look for Python paths on startup. |
4 | -v verbose output (detailed trace on import statements). |
5 | -X disable class-based built-in exceptions (just use strings); obsolete starting with version 1.6. |
6 | -c cmd run Python script sent in as cmd string |
7 | file run Python script from given file |
Script from the Command-line
A Python script can be executed at command line by invoking the interpreter on your application, as in the following −
$python script.py # Unix/Linux or python% script.py # Unix/Linux or C: >python script.py # Windows/DOS
Note − Be sure the file permission mode allows execution.
Integrated Development Environment
You can run Python from a Graphical User Interface (GUI) environment as well, if you have a GUI application on your system that supports Python.
- Unix − IDLE is the very first Unix IDE for Python.
- Windows − PythonWin is the first Windows interface for Python and is an IDE with a GUI.
- Macintosh − The Macintosh version of Python along with the IDLE IDE is available from the main website, downloadable as either MacBinary or BinHex'd files.
If you are not able to set up the environment properly, then you can take help from your system admin. Make sure the Python environment is properly set up and working perfectly fine.
- Related Articles
- How to run Python Program?
- How to run a java program
- How do I run a Python program under Windows?
- Run a Python program from PHP
- How to run Perl Program?
- How to run Java package program
- How to run JavaTuples program in Eclipse?
- How to compile and run the C++ program?
- How to run Python functions from command line?
- How to make loops run faster using Python?
- How to run Python code on Google Colaboratory?
- How to compile & run a Java program using Command Prompt?\n
- How to use Boto3 library in Python to run a Glue Job?
- Program to implement run length string decoding iterator class in Python
- Program to encode a string in normal form to its run-length form in Python
