How to run Python script on terminal

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!