How do I make a program written in python open with two click’s made one executable?

Asked

Viewed 5,900 times

5

An example:

#!/usr/bin/python3
# coding: utf-8

# window.py

from gi.repository import Gtk

class App(Gtk.Window):
    def __init__(self):
        super(Gtk.Window, self).__init__(title='Hello World')
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_size_request(600, 400)
        self.set_keep_above(True)
        self.set_modal(True)
        self.set_icon_name('Hello World')
        self.set_deletable(True)
        self.set_opacity(1)
        self.set_skip_pager_hint(True)
        self.set_skip_taskbar_hint(False)
        self.set_auto_startup_notification(False)
        self.set_border_width(10)

main = App()
main.connect("delete-event", Gtk.main_quit)
main.show_all()
Gtk.main()

How do I open this my script by giving two click done one executable?

  • 1

    Which operating system? if it is windows, you can start by creating a . bat file

  • good i want to create mutiplataforma preference but if Voce knows some recipe for windows can say @psantos

  • see my answer

  • I’m waiting for windows to boot for me to test

3 answers

5


For Windows, Create a . bat file with content similar to this:

@echo off
python c:\teu_script.py %*
pause

You must have python installed and command python recognized.

Or you can create the executable from Pyinstaller (http://www.pyinstaller.org/)

On linux, you can add the "shebang" at the beginning of your python script which will automatically be recognized as a python program:

#!/usr/bin/env python

It is necessary to make the same script executable with the following command:

chmod +x seu_script_python.py

  • I tested the pyintaller here worked, but when I put the executable on my desktop did not pick up anymore, this program only makes an englomention I do not recommend, I’ll have to do dirty work anyway set where each file will be installed and let python run the script is the way but thanks for the help

1

Use pyinstaller. This will turn your Python into a .exe. The options are:

pyinstaller --onefile < tranforma ele em um arquivo só
            --noconsole < desabilita o console
            --icon < coloca um icon no seu .exe

You can run, for example:

pyinstaller --onefile teste.py --noconsole

pip install pyinstaller

0

I use cx_freeze, this program creates the executable file, but when creating the file it is accompanied by other files needed at the time of execution, ie a folder is created with a dll + the executable file. Unfortunately I could not join all created files in one.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.