How to run Python script on terminal

I want to run a Python script in a terminal, but I do not know how to do this? I already saved a file called gameover.py in / User / luca / Documents / python.

+53
python terminal macos
Jan 31 '14 at 23:51
source share
5 answers

You need python installed on your system. Then you can run this in the terminal in the correct directory:

python gameover.py 
+58
Jan 31 '14 at 23:53
source share

You can execute your file using the following:

 python /Users/luca/Documents/python/gameover.py 

You can also run the file by going to the path of the file you want to run and typing:

 python gameover.py 
+18
Nov 27 '14 at 21:02
source share

It depends on which version of python is installed on your system. See below.

If you have Python version 2. *, you should run this command

 python gameover.py 

But if you have Python version 3. *, you should run this command

 python3 gameover.py 

Because for a MAC with Python version 3. * you get a command not found error

if you run "python gameover.py"

+9
Mar 26 '16 at 20:25
source share

First of all, you need to go to the location of the file you are trying to execute, so in the terminal:

 cd ~/Documents/python 

Now you can execute your file:

 python gameover.py 
+4
Feb 01 '14 at 0:14
source share

If you work with Ubuntu, sometimes you need to work as sudo :

For Python2:

 sudo python gameover.py 

For Python3:

 sudo python3 gameover.py 
+2
Apr 19 '17 at 5:27
source share



All Articles