",line 1错误" /> ",line 1错误 - 秒客网" />

第一个Python程序hello.py提示出现File "",line 1错误

时间:2023-03-09 17:06:06
第一个Python程序hello.py提示出现File "<stdin>",line 1错误

写第一个Python程序hello.py,内容仅有一句,print 'hello world',

运行 Python hello.py 出错,提示:

File "<stdin>" , line 1
python hello.py

SyntaxError:invalid syntax

原因:

在shell脚本中,运行shell脚本命令;在Python命令行中,运行Python代码。然而,“python hello.py”是一个脚本命令,不是python代码。

因此,退出python命令行,直接cd到hello.py所在目录,运行python hello.py,即可。

若是非要在python命令行中运行,输入print("hello world")即可。