How To Run Python Program In Terminal
Chapter:
Python
Last Updated:
14-05-2023 12:10:04 UTC
Program:
/* ............... START ............... */
''' Once you're in the correct directory, you can run the Python program using the
python command followed by the name of the Python file. '''
python my_program.py
''' If you have both Python 2 and Python 3 installed, you may need to use python3 instead of python
to specify the Python 3 interpreter explicitly: '''
python3 my_program.py
/* ............... END ............... */
Notes:
-
To run a Python program in the terminal, you can follow these steps:
- Open a terminal or command prompt on your computer.Navigate to the directory where your Python program is located. You can use the cd command (change directory) to move to the appropriate location.For example, if your Python program is in the Documents folder and you're using a Unix-based system (such as macOS or Linux), you can use the following command to navigate to the directory:
- ~ cd Documents
- Once you're in the correct directory, you can run the Python program using the python command followed by the name of the Python file.For example, if your Python program is named my_program.py, you can run it with the following command:
- ~ python my_program.py
- If you have both Python 2 and Python 3 installed, you may need to use python3 instead of python to specify the Python 3 interpreter explicitly:
- ~python3 my_program.py
- Press the Enter key, and the Python program will run in the terminal. The output, if any, will be displayed in the terminal window.
- Please note that you need to have Python installed on your computer and properly set up in your system's PATH variable for the python or python3 command to be recognized.
Tags
How to run Python script in Linux #How To Run Python Program In Terminal #How to run a Python script