I have at the top of the file #!/usr/bin/env python
. So it should work when I run the file? But it doesnt. It works when I use python file.py
tho
#!/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 is 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*
Chris makes an excellent suggestion in the comments to the question, and Peter's answer covers what you should do if Chris' suggestion doesn't work and you are in the sudoer group on your system (i.e. if you can modify files other than those belonging to your user). What follows could be your next option.
In a command shell, type:
which python
this command will tell you where your working installation of python is located. Then you can modify the shebang line in your python file accordingly. For example, on my system:
$ which python
/usr/bin/python
thus my shebang would be:
#!/usr/bin/python
Be aware that this will make your file work on your system but it's highly probable it will make it not runnable on other ones...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With