#! / usr / bin / env python: command not found and permission denied

I have at the top of the file #!/usr/bin/env python. So should it work when I run the file? But this is not so. It works when I use python file.pytho

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk 

class App1:
  def __init__(self):
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.show()

  def main(self):
    gtk.main()

if __name__ == "__main__":
  app = App1()
  app.main()

Python Here's what happened:

jiewmeng@jiewmeng:/labs/projects/learnPython$ app1.py
app1.py: command not found
jiewmeng@jiewmeng:/labs/projects/learnPython$ ./app1.py
bash: ./app1.py: Permission denied
jiewmeng@jiewmeng:/labs/projects/learnPython$ ll
total 12
drwxr-xr-x 2 jiewmeng jiewmeng 4096 2011-07-16 22:08 ./
drwxr-xr-x 4 jiewmeng jiewmeng 4096 2011-07-16 21:45 ../
-rwxrwxr-x 1 jiewmeng jiewmeng  256 2011-07-16 22:05 app1.py*
+5
source share
3 answers

Chris makes a wonderful suggestion in the comments on this question, and Peter says what you should do if Chris’s suggestion doesn’t work and you are in the sudoer group on your system (that is, if you can modify files other than those belonging to your user). The next may be your next option.

In the shell, type:

which python

, python. shebang python. , :

$ which python
/usr/bin/python

shebang :

#!/usr/bin/python

, , , ...

+6

, :/usr/bin/env . sudo chmod 755 /usr/bin/env. , - /usr/bin/env.

+1

What happened to python base code, for example:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

print "Hello World !"

Perhaps the problem is with GTK or another, but not with #!/usr/bin/env python?

0
source

All Articles