Python3 shebang 线路未按预期工作
Python3 shebang line not working as expected
我在 Solaris 环境中 运行ning 一个 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
编辑: 我可以确认 test.py 中的行结尾是 Unix
编辑 2: od
输出
$ 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
编辑 3: shell 是 bash
$ echo [=13=]
/bin/bash
一切重要的事情都发生在评论中。我简单总结一下吧。
在彻底检查 shebang 行本身是否正确编写后,考虑了来自其他系统的类似错误(我知道)。
事实证明,Solaris 受到与讨论和解决的相同问题的影响 here。摘要:shebang 行要求解释器是二进制文件,而不是另一个脚本。
我在 Solaris 环境中 运行ning 一个 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
编辑: 我可以确认 test.py 中的行结尾是 Unix
编辑 2: od
输出
$ 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
编辑 3: shell 是 bash
$ echo [=13=]
/bin/bash
一切重要的事情都发生在评论中。我简单总结一下吧。
在彻底检查 shebang 行本身是否正确编写后,考虑了来自其他系统的类似错误(我知道)。
事实证明,Solaris 受到与讨论和解决的相同问题的影响 here。摘要:shebang 行要求解释器是二进制文件,而不是另一个脚本。