[Tutor] executing with double click on linux

Alfonso euoar at yahoo.es
Fri Oct 13 21:33:49 CEST 2006


Jonathon Sisson escribió:
> Alfonso wrote:
>   
>> Sorry for the too obvious question. I'm new to python and have no idea 
>> how can I make execute a compiled .pyc with a double click in linux, 
>> with gnome. Trying to double click in a .py gives allways the question 
>> wether I want to execute the text file, or read it. (This behaviour can 
>> be changed with gconf-editor, but as it is for security matters, I would 
>> prefer to execute the .pyc with a double click). I have tried to 
>> associate python to the .pyc (first time I executed it there was no 
>> programm associated), but it doesn't work.
>>
>>     
>
> I don't know how much Linux experience you have (judging by the
> "double-click" concept, I'm assuming you're coming from a Windows
> background or are perhaps catering to users with only a Windows
> background) (correct me if I'm wrong)...so I'm going to break this down
> as much as I can.
>
> .pyc files are considered binary files by Linux.  As such, bash attempts
> to execute them as binary (ELF, etc...), which obviously won't work.  If
> you really need to have double-click/execute functionality, consider
> writing a small shell script to execute the .pyc file for you.
>
> For instance, let's say you have a python script "foo.py" and a compiled
> python script "foo.pyc".  If you attempt to run foo.py from the shell
> and you have a proper header (i.e. #!/usr/bin/python), then bash can
> execute the script.  I'm assuming that GNOME has similar functionality
> (I prefer Fluxbox to either GNOME or KDE), which allows your .py files
> to execute directly.  .pyc, however, even with a file association, fails
> to launch...on my system, I get this error:
>
> $ ./foo.pyc
> bash: ./foo.pyc: cannot execute binary file
>
> bash recognizes the file as binary, but it fails to launch as an ELF
> binary (or whatever you're set up to run).  To fix it, simply write a
> shell script as such:
>
> <code>
> #!/bin/sh
>
> python /home/me/scripts/foo.pyc
>
> </code>
>
> Name the script whatever you want (i.e. foo.sh) then run from the
> commandline:
>
> $ chmod 700 foo.sh
>
> This gives the script read/write/execute permissions for the owner of
> the script...if you require read/write/execute/etc...for group or all,
> change 700 to whatever you need.  (i.e. 755 for rwxr-xr-x permissions)
>
> (Alternatively you can right click on the shell script and set
> permissions graphically...whichever you prefer)  Now, you should be able
> to double-click the script (or preferably a shortcut to the script on
> your desktop), which will launch the compiled python module for you.  If
> this seems like a lot of work, then perhaps you could write a shell
> script to automate the task of creating the shell script and setting
> permissions each time you create a new .pyc...doh?
>
> Hope this is a satisfactory answer...and if anyone knows something I
> have overlooked, please let Alfonso and I know.
>
> Jonathon
>
>
>   
>> Thank you for your answer.
>>
>> 		
>> ______________________________________________ 
>> LLama Gratis a cualquier PC del Mundo. 
>> Llamadas a fijos y móviles desde 1 céntimo por minuto. 
>> http://es.voice.yahoo.com
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>     
>
>   
Thank you very much for your answer.

Both true, coming from windows, three years with linux. I don't have any 
fear to executing from the shell, but It's not the same thing with some 
of my friends, totally new to linux, and not very much friends of the 
console. I would like to distribute to them my python programms (when I 
have the knolowdge to writte something decent with python :) ).

 If I use a bash script I have the same "problem" that with executing 
the .py. Gnome asks wether you want to execute or read it, etc. This is 
due to security reasons, and can be disabled using the tool 
gconf-editor, you can change that behaviour so that the files are 
allways executed or opened with a text editor. But I didn't want to 
change that, and I thought this could be easily avoided just executing 
the .pyc files, because I have programmed with mono (.net) in linux and 
that works so. I mean, if I'm not mistaked .pyc are compiled in 
intermediate language files, just like .exe in .net/mono. With mono all 
I have to do was chmod at the .exe, then changing the programm with 
which the .exe is opened (to mono) and that works fine for me, it can be 
opened with a double click. But it's not an elf binary, I think...

I think there must be a way to execute with a launcher the programm 
without being asked each time. As it is for example with bittornado or 
bittorrent, both written in python and both are executed from the 
applications menu or from a launcher at the desktop with no intermediate 
question about if you want to show or execute the file, or just to 
cancel the action. In fact, when I execute bittornado it's a file called 
btdownoladgui.bittornado which is executed. But it's python code. If I 
try to do something similar (executing a file with a not .py extension, 
but written in python), gnome will complain, that the file is python 
script with a different extension, and that as it could be a security 
risk it won't be executed. Could it be that those applications, 
bittornado, bittorrent, etc., modify some gnome configuration files when 
they are installed, to avoid that default behaviour?

Don't know if I'm explaining right (sorry for my bad english). Resume: 
anyone that has programmed a python app and created a launcher, in 
gnome, how do you make it so that the file is executed directly after 
clicking on it without showing all this anoying messages each time?

Again, thank you for your answers.


		
______________________________________________ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y móviles desde 1 céntimo por minuto. 
http://es.voice.yahoo.com


More information about the Tutor mailing list