如何在 Windows 命令提示符下运行 python 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39462632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:18:18  来源:igfitidea点击:

how to run python files in windows command prompt?

pythonpython-2.7command-linecmdcommand

提问by Abdullah Bilal

I want to run a python file in my command prompt but it does nothing. These are the screen shots of my program i am testing with and the output the command prompt gives me. enter image description here

我想在我的命令提示符中运行一个 python 文件,但它什么也不做。这些是我正在测试的程序的屏幕截图以及命令提示符给我的输出。 在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Benjamin

First set path of pythonhttps://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows

首先设置https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows 的路径python

and run pythonfile

并运行python文件

python filename.py

python filename.py

command line argument with python

python的命令行参数

python filename.py command-line argument

python filename.py command-line argument

回答by Matu

You have to installPythonand add it to PATHon Windows. After that you can try:

您必须使用installPython并将其添加到PATHWindows。之后你可以尝试:

python `C:/pathToFolder/prog.py`

or go to the files directory and execute:

或转到文件目录并执行:

python prog.py

回答by V.Khakhil

First go to the directory where your python script is present by using-

首先使用 - 转到您的python脚本所在的目录

cd path/to/directory

then simply do:

然后简单地做:

python file_name.py