问题
Am encountering this error in Windows Command line,done a wide search but could not get a perfect answer.Please find the error below and help in solving.
python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
>>>
Thanks in Advance,
回答1:
It looks like you are trying to start the Python interpreter by running the command python
.
However the interpreter is already started. It is interpreting python
as a name of a variable, and that name is not defined.
Try this instead and you should hopefully see that your Python installation is working as expected:
print("Hello world!")
回答2:
When you run the Windows Command Prompt, and type in python
, it starts the Python interpreter.
Typing it again tries to interpret python
as a variable, which doesn't exist and thus won't work:
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>
If you're not doing this from the command line, and instead running the Python interpreter (python.exe or IDLE's shell) directly, you are not in the Windows Command Line, and python
is interpreted as a variable, which you have not defined.
来源:https://stackoverflow.com/questions/16857105/nameerror-name-python-is-not-defined