Python3 shebang 线没有按预期工作 [英] Python3 shebang line not working as expected

查看:28
本文介绍了Python3 shebang 线没有按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Solaris 环境中运行 Python 脚本时遇到以下问题.

I'm having the below issue running a Python script in a Solaris environment.

我似乎在 shebang 行上做了一些不正确的事情,但我不知道这是 Python 3 问题还是命令行问题.

It appears I have done something incorrect on the shebang line, but I can't tell if this is a Python 3 issue or a command line issue.

但我怀疑它以某种方式与 shebang 行有关,因为当我在命令行上显式运行 Python 解释器时没有问题.

But I suspect it's related to the shebang line somehow since when I explicitly run the Python interpreter on the command line there is no problem.

路径 /opt/python3.3.2/bin/python3.3 是我的系统管理员选择放置 Python 的位置,我不知道这个位置在 Solaris 上有什么问题.

The path /opt/python3.3.2/bin/python3.3 is the location where my sysadmin chose to put Python, I don't know of this location is problematic somehow on 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

I can confirm the line endings in test.py are 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

EDIT 3: shell is bash

$ echo $0
/bin/bash

推荐答案

所有重要的事情都发生在评论中.让我简单总结一下.

Everything important happened it the comments. Let me just summarize it.

在彻底检查 shebang 行本身是否正确编写后,考虑到了来自其他系统的类似错误 - 我知道 - 被考虑在内.

After thorough checks that the shebang line itself is correctly written, a similar bug from other system - that I was aware of - was taken into consideration.

事实证明,Solaris 受到与讨论和解决的相同问题的影响 此处.总结:shebang 行要求解释器是一个二进制文件,而不是另一个脚本.

As it turned out, Solaris is affected by the same issue as was discussed and solved here. Summary: The shebang line requires interpreter to be a binary, not another script.

这篇关于Python3 shebang 线没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆