2013-05-31 188 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