Please tell me how to execute python file in Ubuntu by double clicking on file.

Thomas Jollans tjol at tjol.eu
Mon Dec 4 19:10:02 EST 2017


On 05/12/17 01:03, Michael Torrie wrote:
> On 12/04/2017 04:49 AM, Thomas Jollans wrote:
>> On 2017-12-04 10:48, dhananjaysingh091298 at gmail.com wrote:
>>> Respected Sir/Mam,
>>>         I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double click in python program (Dhananjay.py),it is opening in Text Editor by Default in Ubuntu.I want to run this program when i double click on it as any *.Exe file executes as in Window.
>>> Sir please help me.
>>>
>>
>> https://askubuntu.com/a/544544
> 
> Oops! You misread his question. The question was, how can he run a
> python script by simply double clicking on it in the file browser in
> Ubuntu?

No, I was just being (rudely, perhaps) terse.

The file browser used by default in Ubuntu/Gnome (aka Nautilus) has a
setting, as described in that Ask Ubuntu answer, that makes it execute
scripts, Python or otherwise, on double click (as long as they have a
correct #! line and are executable)

> 
> Now I don't know the answer to that question, but I can say that nearly
> all the time you just don't want to do that anyway, for reasons I state
> below.

I absolutely agree.

> 
> Instead, open a terminal, change to the directory where you python
> script is and either run it directly (if it's chmod'd as exectuable)
> using "./myscript.py" or use the python interpreter: "python3
> /path/to/myscript.py"
> 
> The reason scripts are rarely launched from the file browser like you
> want to do is that often scripts communicate with the user via standard
> out, so you need to run them from a terminal.
> 
> There are some GUI programs written in Python, but those are usually
> launched from a .desktop file shortcut.
> 
> 
> 




More information about the Python-list mailing list