Python 脚本不会运行

标签 python

我在文件夹 ~/Scripts 中有一些脚本已添加到路径中。所以我试图测试我是否可以运行它们,只是通过调用它们。我在 Linux Mint 11 上安装了 Python 3.1。

user@pc ~/Scripts $ python aek.py
AEK

user@pc ~/Scripts $ aek.py

/home/user/Scripts/aek.py: line 1: syntax error near unexpected token `'AEK''

/home/user/Scripts/aek.py: line 1: `print('AEK')'

代码就这么一行:

print('AEK')

最佳答案

您需要在脚本的第一行添加:

#!/usr/bin/python

或者您想要使用的任何解释器。否则,shell(可能是 bash)会认为它是 shell 脚本并阻塞。

如果你想从路径中获取 python 解释器,请改为:

#!/usr/bin/env python

有关更多信息,请参阅 shebang .

关于Python 脚本不会运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7366568/

相关文章:

Python 2.7 : Print to File

python - 串行端口在重写的 Python 代码中不起作用

python - 从一个列表中查找以另一个列表中的字符串开头的字符串

python - 导入错误 : Could not import settings

Python - 字符串中的第一个和最后一个字符必须是字母数字,否则删除

python - 为什么 Python pep-8 强烈建议在制表符上使用空格进行缩进?

python - Flask-Testing 和 Flask-SQLAlchemy : first_or_404()

python - 为什么会出现 fatal error : 'yaml.h' file not found when installing PyYAML?

python - Tkinter 文本搜索框 'bad text index'

python - 错误谷歌 API : "Credentials in post body and basic Authorization header do not match"