I'm having the below issue running a Python script in a Solaris environment.
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.
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.
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
EDIT: I can confirm the line endings in test.py are 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 is bash
$ echo $0
/bin/bash
Everything important happened it the comments. Let me just summarize it.
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.
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.