I want to run a Python script in terminal but I don't know how? I already have saved a file called gameover.py in /User/luca/Documents/python.
问题:
回答1:
You need python installed on your system. Then you can run this in the terminal in the correct directory:
python gameover.py
回答2:
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
回答3:
This Depends on what version of python is installed on you system. See below.
If You have Python 2.* version you have to run this command
python gameover.py
But if you have Python 3.* version you have to run this command
python3 gameover.py
Because for MAC with Python version 3.* you will get command not found error
if you run "python gameover.py"
回答4:
First of all, you need to move to the location of the file you are trying to execute, so in a Terminal:
cd ~/Documents/python
Now, you should be able to execute your file:
python gameover.py
回答5:
If you are working with Ubuntu, sometimes you need to run as sudo
:
For Python2:
sudo python gameover.py
For Python3:
sudo python3 gameover.py