Running Python File in Terminal
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
- 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
Just prefix the script's filename with python
. E.g.:
python filename.py
It's also worth mentioning that by adding a -i
flag after python
, you can keep your session running for further coding. Like this:
python -i <file_name.py>