2013-05-31 60 views
2

我在Windows命令行中遇到此错误,做了大量的搜索,但无法获得完美的答案。请在下面找到错误并帮助解决。NameError:未定义名称'python'

python 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
NameError: name 'python' is not defined 
>>> 

由于事先

+0

你是如何得到这个回溯?你输入了什么?我猜你试图做'python'来启动解释器,然后再次输入'python',这被解释为一个变量名。 –

+0

你没有在'python'这个单词前加上'>>>',对吧? – Elazar

回答

18

它看起来像你正试图通过运行命令python启动Python解释器。

但是解释器已经启动。它将python解释为变量的名称,并且该名称未定义。

试试这个,你应该希望看到你的Python安装工作正常:

print("Hello world!") 
+0

这种类型的工作得很好,但当我输入只是“python它显示错误为名称错误:python未定义。这是什么意思?>>> print(”hello world“) hello world >> > – user13050

8

当您运行Windows命令提示符,然后键入python,它会启动Python解释器。

再输入一次试图解释python作为一个变量,它不存在,因此将无法正常工作:

Microsoft Windows [Version 6.1.7601] 
Copyright (c) 2009 Microsoft Corporation. All rights reserved. 

C:\Users\USER>python 
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> python 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
NameError: name 'python' is not defined 
>>> print("interpreter has started") 
interpreter has started 
>>> quit() # leave the interpreter, and go back to the command line 

C:\Users\USER> 

如果你没有在命令行这样做,而是运行直接使用Python解释器(python.exe或IDLE的shell),您不在Windows命令行中,并且python被解释为您尚未定义的变量。

+0

可能他根本没有运行命令行,而是直接运行python解释器。 – Elazar