简体   繁体   English

Python脚本将无法运行

[英]Python script won't run

I have some scripts in the folder ~/Scripts which I have added to the path. 我在路径中添加了〜/ Scripts文件夹中的一些脚本。 So I tried to test if I can run them, just by calling them. 所以我试着通过调用它们来测试我是否可以运行它们。 I have python 3.1 over Linux Mint 11. 我在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')'

The code is just this one line: 代码就是这一行:

print('AEK')

You need to add the very first line in your script: 您需要在脚本中添加第一行:

#!/usr/bin/python

Or whatever interpreter you want to use. 或者你想要使用的任何翻译。 If not, the shell (probably bash) will think that it is a shell script and choke. 如果没有,shell(可能是bash)会认为它是一个shell脚本并且阻塞。

If you want to get the python interpreter from the path, do instead: 如果你想从路径中获取python解释器,请改为:

#!/usr/bin/env python

For extra information, see shebang . 有关其他信息,请参阅shebang

The error is not a python error but a shell error. 该错误不是python错误,而是shell错误。

You should add a shebang line if you don't run them via the python executable. 如果你不通过python可执行文件运行它们,你应该添加一个shebang行。

And it most definitely is not a python2 <-> python3 conflict. 它绝对不是python2 < - > python3冲突。 python2 handles parens here quite well (but there are corner cases where it breaks). python2在这里很好地处理parens(但是有一些它会破坏的角落情况)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM