I have a self-installed python in my user directory in a corporate UNIX SUSE computer (no sudo privilege):
which python
<user>/bin/python/Python-3.6.1/python
I have an executable (chmod 777) sample.py file with this line at the top of the file:
#!<user>/bin/python/Python-3.6.1/python
I can execute the file like this:
python sample.py
But when I run it by itself I get an error:
/full/path/sample.py
/full/path/sample.py: Command not found
I have no idea why it's not working. I'm discombobulated as what might be going wrong since the file is executable, the python path is correct, and the file executes if I put a python command in the front. What am I missing?
EDIT: I tried putting this on top of the file:
#!/usr/bin/env python
Now, I get this error:
: No such file or directory
I tried this to make sure my env is correct
which env
/usr/bin/env
EDIT2:
Yes, I can run the script fine using the shebang command like this:
<user>/bin/python/Python-3.6.1/python /full/path/sample.py
chmod 777is (almost) never the right thing to do. Set only the privileges you actually need. In this case that's most likely755(you get read/write/execute, others get read/execute)python sample.py, can you run/the/full/path/from/shbang sample.py? If yes, then the problem is likely with the formatting of the first line. If no, then either you're pointing at the wrong python binary, or the python installation is broken./abc/xyz/disks/ab.xyz.123/myname/bin/python/Python-3.6.1/python. The only odd thing I see is periods and hyphens. The full path of the python file is also very similar to this.