Python3 shebang line doesn't work as expected
I have below problem with Python script on Solaris environment.
It looks like I did something wrong on the shebang line, but I can't tell if this is a Python 3 issue or a command line issue.
But I suspect it has something to do with the shebang line in some way, since when I explicitly run the Python interpreter on the command line, there is no problem.
Path /opt/python3.3.2/bin/python3.3
is where my sysadmin decided to put Python, I don't know how this place is somehow problematic 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
EDIT: I can confirm line endings in test.py, this is 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: bash shell
$ echo $0
/bin/bash
source to share
All important events happened with comments. Let me just summarize.
After carefully checking that the shebang line itself was spelled correctly, a similar error from another system I was aware of was accounted for.
As it turns out, Solaris is affected by the same issue discussed and resolved here . Summary: The shebang line requires the interpreter to be binary and not another script.
source to share