我在 Solaris 环境中运行 Python 脚本时遇到以下问题。
看来我在 shebang 线上做了一些不正确的事情,但我无法判断这是 Python 3 问题还是命令行问题。
但我怀疑它与 shebang 行有某种关系,因为当我在命令行上显式运行 Python 解释器时没有问题。
路径/opt/python3.3.2/bin/python3.3
是我的系统管理员选择放置 Python 的位置,我不知道这个位置在 Solaris 上是否有问题。
$ uname -a
SunOS ... 5.10 Generic_150401-49 i86pc i386 i86pc Solaris
$ cat test.py
#!/opt/python3.3.2/bin/python3.3
import sys
print("hi")
$ ./test.py
./test.py: line 2: import: command not found
./test.py: line 3: syntax error near unexpected token `"hi"'
./test.py: line 3: `print("hi")'
$ /opt/python3.3.2/bin/python3.3 test.py
hi
EDIT:我可以确认 test.py 中的行结尾是 Unix
EDIT 2: od
output
$ od -c -N 30 test.py
0000000 # ! / o p t / p y t h o n 3 . 3
0000020 . 2 / b i n / p y t h o n 3
0000036
EDIT 3:shell 是 bash
$ echo $0
/bin/bash
一切重要的事情都发生在评论上。我简单总结一下。
在彻底检查 shebang 行本身是否正确编写之后,我注意到了来自其他系统的类似错误 - 被考虑在内。
事实证明,Solaris 受到了与讨论和解决相同的问题的影响here https://stackoverflow.com/questions/9988125/shebang-pointing-to-script-also-having-shebang-is-effectively-ignored。概括:shebang 行要求解释器是二进制文件,而不是另一个脚本.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)