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.
我想在终端运行Python脚本,但我不知道如何?我已经在/ User / luca / Documents / python中保存了一个名为gameover.py的文件。
6 个解决方案
#1
69
You need python installed on your system. Then you can run this in the terminal in the correct directory:
您需要在系统上安装python。然后你可以在终端的正确目录中运行它:
python gameover.py
#2
18
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
9
This Depends on what version of python is installed on you system. See below.
这取决于您系统上安装的python版本。见下文。
If You have Python 2.* version you have to run this command
如果您有Python 2. *版本,则必须运行此命令
python gameover.py
But if you have Python 3.* version you have to run this command
但是如果你有Python 3. *版本,你必须运行这个命令
python3 gameover.py
Because for MAC with Python version 3.* you will get command not found error
因为对于Python版本为3. *您将获得命令未找到错误
if you run "python gameover.py"
如果你运行“python gameover.py”
#4
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
3
If you are working with Ubuntu, sometimes you need to run as sudo
:
如果您正在使用Ubuntu,有时您需要以sudo身份运行:
For Python2:
对于Python2:
sudo python gameover.py
For Python3:
对于Python3:
sudo python3 gameover.py
#6
0
You first must install python. Mac comes with python 2.7 installed to install Python 3 you can follow this tutorial: http://docs.python-guide.org/en/latest/starting/install3/osx/.
首先必须安装python。安装python 2.7安装Python以安装Python 3,您可以按照本教程:http://docs.python-guide.org/en/latest/starting/install3/osx/。
To run the program you can then copy and paste in this code:
要运行该程序,您可以复制并粘贴此代码:
python /Users/luca/Documents/python/gameover.py
Or you can go to the directory of the file with cd
followed by the folder. When you are in the folder you can then python YourFile.py
.
或者您可以使用cd后跟文件夹转到文件目录。当你在文件夹中时,你可以python YourFile.py。
#1
69
You need python installed on your system. Then you can run this in the terminal in the correct directory:
您需要在系统上安装python。然后你可以在终端的正确目录中运行它:
python gameover.py
#2
18
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
9
This Depends on what version of python is installed on you system. See below.
这取决于您系统上安装的python版本。见下文。
If You have Python 2.* version you have to run this command
如果您有Python 2. *版本,则必须运行此命令
python gameover.py
But if you have Python 3.* version you have to run this command
但是如果你有Python 3. *版本,你必须运行这个命令
python3 gameover.py
Because for MAC with Python version 3.* you will get command not found error
因为对于Python版本为3. *您将获得命令未找到错误
if you run "python gameover.py"
如果你运行“python gameover.py”
#4
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
3
If you are working with Ubuntu, sometimes you need to run as sudo
:
如果您正在使用Ubuntu,有时您需要以sudo身份运行:
For Python2:
对于Python2:
sudo python gameover.py
For Python3:
对于Python3:
sudo python3 gameover.py
#6
0
You first must install python. Mac comes with python 2.7 installed to install Python 3 you can follow this tutorial: http://docs.python-guide.org/en/latest/starting/install3/osx/.
首先必须安装python。安装python 2.7安装Python以安装Python 3,您可以按照本教程:http://docs.python-guide.org/en/latest/starting/install3/osx/。
To run the program you can then copy and paste in this code:
要运行该程序,您可以复制并粘贴此代码:
python /Users/luca/Documents/python/gameover.py
Or you can go to the directory of the file with cd
followed by the folder. When you are in the folder you can then python YourFile.py
.
或者您可以使用cd后跟文件夹转到文件目录。当你在文件夹中时,你可以python YourFile.py。