我在Windows命令行中遇到了这个错误,进行了广泛的搜索,但没有找到完美的答案。请看下面的错误并帮助解决。
python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
>>>
提前致谢,
看起来你试图通过运行命令python
启动Python解释器。
但是解释器已经启动了。它将python
解释为变量名,并且该名称未定义。
请尝试以下命令,您应该会看到您的Python安装按预期工作:
print("Hello world!")
- user13050
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
被解释为变量,而您尚未定义。
python
命令来启动解释器,然后再次输入python
,但它被解释为变量名。 - Rushy Panchal