Im having a problem. I am sick of using a problem such as dr python or geany which when you execute the program a script is made along with the python script which alows it to execute. Well anyway i want to be able to use gedit and then execute the script.I have tryed adding these lines:

Which one should work?

def main():
	print "main"
def main():
	print "main"

If this line of code worked then I would expect to just double click the python scripts and hope it runs in a terminal.

How could i fix this?

Mr.popo :)

Recommended Answers

All 9 Replies

I am presuming you are on Linux.


#! /usr/bin/env python

print "Success!"

Hope this helps.

[EDIT] Oh wait. I just re-read your original post. You want to double click the python file? What window manager are you using?

Gnome if thats what you mean...
Sorry if its not.

Gnome shouldn't have any trouble executing py files by double-click.

1. Make sure you have the proper header in the file (as per my last post).

2. Failing that, make sure that python is installed with the proper MIME type. If not, you can do it yourself as per the documentation here.

Hope this helps.

Thank you for your help. I shall check the documentation out now :)

I added the header line which you gave me then I went to properties of the file. I then ticked allow execute in pemissions. I then double clicked the file and it gave me the option of run and display(which did nothing) and run in terminal which runs fine.

My question is what the user have to do if it was a commercial python script?#


That's actually a tough question. Most of the window managers I am familiar with (which isn't many) will properly execute a text file beginning with the magic words: #! /usr/bin/python or #! /usr/bin/env python For a specific distribution, python should be able to install properly so that you don't have to worry about it. But, in the end, it is the choice of window manager that makes all the difference. In essence, it is the end-user's responsibility to make it double-click executable. Yeah, stupid, I know.

If you want to be most robust, you can try to do some tricks:
1. Rename it from to (making sure the magic lines are still in the header).
2. Use something like py2exe to compile your script into an actual executable (ELF, in your case).
3. In your installation script, check to see if the user is using a known window manager and update the wm from the installation script (but ask first!).
4. Use a utility like makeself. (This is really just a variation on #1.)

Sorry I couldn't be of more help.

Bit more clearer now. Thanks

What if the user has not python installed? Is it possible to compile a python script ? I mean a conversion python to C/C++, Pascal, kylix ....?

Yes. There's a tool called py2exe. Here is the link:
It can also compile resource files in the same exe, to keep it clean

Yes. There's a tool called py2exe. Here is the link:
It can also compile resource files in the same exe, to keep it clean

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.