简体   繁体   English

从命令提示符运行python脚本

[英]Running a python script from command prompt

I'm working on a tutorial for a big data class and am having trouble in the command line (Windows 7 Pro). 我正在编写有关大数据类的教程,并且在命令行中遇到问题(Windows 7 Pro)。 I'm not very familiar with the command line environment so this is probably something simple, but here goes: 我对命令行环境不是很熟悉,因此这可能很简单,但是这里有:

I have a python script called mapper.py that is stored in the directory 我有一个名为mapper.py的python脚本,存储在目录中

E:\Documents\School\Math\M 461\MapReduce\PythonScripts

and a file named 和一个名为

Medicare_Provider_Util_Payment_PUF_CY2013.txt

that is stored in 存储在

E:\Documents\School\Math\M 461\MapReduce\Data

Python (Anaconda) is installed at C:\\Program Files\\Anaconda3 . Python(Anaconda)安装在C:\\Program Files\\Anaconda3 I'm trying to feed the file to the script and execute it from the command line using 我正在尝试将文件提供给脚本并使用以下命令从命令行执行它

type Medicare_Provider_Util_Payment_PUF_CY2013.txt
| 'C:\Program Files\Anaconda3\python' mapper.py

I use the apostrophes because otherwise it doesn't like the space in Program Files. 我使用撇号,因为否则它不喜欢Program Files中的空格。 However, when I execute this command it says that "The filename, directory name, or volume label syntax is incorrect." 但是,当我执行此命令时,它说“文件名,目录名或卷标签语法不正确。” I'm not sure where to go from here so any guidance would be appreciated. 我不确定从这里要去哪里,所以任何指导将不胜感激。

The text file and the Python file aren't in the same directory, so your example can't work. 文本文件和Python文件不在同一目录中,因此您的示例无法正常工作。 Try this series of commands in at your command prompt: 在命令提示符处尝试以下一系列命令:

First, make the common parent the current directory 首先,使公共父目录成为当前目录

E:
cd E:\Documents\School\Math\M 461\MapReduce

Then run your script, giving the path to the data and python files: 然后运行您的脚本,提供数据和python文件的路径:

type Data\Medicare_Provider_Util_Payment_PUF_CY2013.txt | 'C:\Program Files\Anaconda3\python' PythonScripts\mapper.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM