2

I have a very simple script called blah.py which looks like this:

#!/space/jazz/1/users/gwarner/anaconda/bin python
print 'here'

My which python returns /space/jazz/1/users/gwarner/anaconda/bin/python and ls -l blah.py returns -rwxrwxr-x 1 gwarner gwarner 64 Jul 13 14:16 blah.py. My username is gwarner. However, when I try to execute this script from the directory it lives in using ./blah.py I get ./blah.py: Permission denied. It runs correctly when I execute it using python blah.py. What is going on?

G Warner
  • 1,309
  • 1
  • 15
  • 27

3 Answers3

3

I think you have an extra space in the shebang line... try this:

#!/space/jazz/1/users/gwarner/anaconda/bin/python
Chris Sprague
  • 740
  • 1
  • 12
  • 22
0

Make sure that the /space/jazz/1/users/gwarner/anaconda/bin file does indeed have executable permissions set.

Brian Showalter
  • 4,321
  • 2
  • 26
  • 29
-2

You are trying to run blah.py as an executable file. For that you might need to run this on the terminal

sudo chmod +x blah.py

to change the permission of the file and make it executable.

Himanshu Mishra
  • 8,510
  • 12
  • 37
  • 74
  • 1
    OP said the file's permissions are reported as `-rwxrwxr-x`, so isn't it already executable? – Chris Sprague Jul 13 '15 at 18:25
  • If I am correct the highest permission level is `-rwxrwxrwx` at 777. So, maybe the change is required. @GWarner did you try doing it? – Himanshu Mishra Jul 13 '15 at 18:30
  • @o11c I've clearly stated about the permission changes. How can you coin the term 'careless'? – Himanshu Mishra Jul 13 '15 at 18:31
  • 1
    @HimanshuMishra 777 is the most permissive, but this user owns the script file, making it globally permissive is unnecessary and possibly dangerous, as it allows any other user to read and even modify the file. – Dan Lowe Jul 13 '15 at 18:33
  • 1
    @HimanshuMishra you should NEVER EVER use `sudo` unless you know exactly what privilege you lack without it and why you can't find another way. It is NOT some magical "fix all errors" command. `sudo` is EXTREMELY dangerous; using it in this case where it is obviously unneeded is a REALLY bad habit. – o11c Jul 13 '15 at 19:11