1
PROMPT> which python
/usr/local/bin/python

PROMPT> ls -al
total 8
drwxr-xr-x   3 jon   102B Aug 27 20:15 ./
drwxrwxr-x  21 jon   714B Aug 27 20:15 ../
-rwxr-xr-x   1 jon    54B Aug 27 20:15 build*

PROMPT> cat build
#! /usr/local/bin/ python
print 'hello world - build'

PROMPT> ./build
-bash: ./build: /usr/local/bin/: bad interpreter: Permission denied

What am I doing wrong?

jononomo
  • 12,340
  • 25
  • 77
  • 134
  • 1
    Well, I edited the file to remove the space before the word python on the first line, and that seems to have done the trick. – jononomo Aug 28 '13 at 00:22

3 Answers3

2

Get rid of the spaces in #! /usr/local/bin/ python so it's #!/usr/local/bin/python. You may also want to make it #!/usr/bin/env python, which will select the first Python interpreter in your path, but that's not recommended for published modules. (Although, neither is /usr/local/bin/python).

Community
  • 1
  • 1
detly
  • 26,649
  • 13
  • 85
  • 142
  • Thanks -- I just figured that out. What I would really like to do, however, is have the first line read something like `#! $APP_HOME/app_venv/bin/python` - is there any way I can use an environment variable in the first line? – jononomo Aug 28 '13 at 00:25
  • @JonCrowell - You can't really, see *[How can I use environment variables in my shebang?](http://unix.stackexchange.com/questions/20880/how-can-i-use-environment-variables-in-my-shebang)*. (*Shebang* line refers to the `#!...` line.) – detly Aug 28 '13 at 00:26
  • Note also that you still have a space after `!` in your comment! – detly Aug 28 '13 at 00:27
  • @JonCrowell - My workflow in virtualenvs is to have a single bash/sh script that contains the `$PATH` modifications, etc. I need, and do `. venv-p2.sh` (or `. venv-p3.sh`, `. venv-num.sh`, etc). Clunky, but I don't know of a simpler way to do it. – detly Aug 28 '13 at 00:40
2

Your shebang has too many spaces. Try

#!/usr/local/bin/python

Another common form calls 'env' to find which python to use so that you are not dependent on paths that tend to be different depending on how python was installed.

#!/usr/bin/env python
tdelaney
  • 55,698
  • 4
  • 59
  • 89
2

You have space between /bin/ and python.

HTH, Phil

Phil
  • 827
  • 2
  • 10
  • 23