Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Python script on terminal?

I want to run a Python script in Terminal, but I don't know how? I already have a saved file called gameover.py in the directory "/User/luca/Documents/python".

like image 431
SnakeEyes Avatar asked Jan 31 '14 23:01

SnakeEyes


People also ask

How do I run a .PY file in terminal?

Running a Script Open the terminal by searching for it in the dashboard or pressing Ctrl + Alt + T . Navigate the terminal to the directory where the script is located using the cd command. Type python SCRIPTNAME.py in the terminal to execute the script.

How do I run a Python script in terminal Mac?

On a Mac system, it is very straight-forward. All you need to do is open Launchpad and search for Terminal , and in the terminal, type Python and boom, it will give you an output with the Python version.

Can you use Python in terminal?

You can start a Python program with the terminal or command line. This works on all platforms (Mac OS, Windows, Linux). To open a terminal on Windows: press the windows key + r key (run program), type cmd or command and press enter.


2 Answers

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

python gameover.py 
like image 80
ferdynator Avatar answered Sep 28 '22 10:09

ferdynator


You can execute your file by using this:

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

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

python gameover.py 
like image 25
bcho04 Avatar answered Sep 28 '22 10:09

bcho04