我在Windows命令行中遇到此错误,进行了广泛的搜索,但无法得到一个完美的答案.请在下面找到错误并帮助解决.
python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
>>>
Run Code Online (Sandbox Code Playgroud)
提前致谢,
Mar*_*ers 29
看起来您正在尝试通过运行命令来启动Python解释器python.
但是解释器已经启动了.它将解释python为变量的名称,并且未定义该名称.
试试这个,你应该希望看到你的Python安装按预期工作:
print("Hello world!")
Run Code Online (Sandbox Code Playgroud)
Rus*_*hal 12
当您运行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>
Run Code Online (Sandbox Code Playgroud)
如果您不是从命令行执行此操作,而是直接运行Python解释器(python.exe或IDLE的shell),则您不在Windows命令行中,并且python被解释为您尚未定义的变量.
| 归档时间: |
|
| 查看次数: |
72600 次 |
| 最近记录: |