IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques tierces Python Discussion :

PyInstaller, un tuto ?


Sujet :

Bibliothèques tierces Python

  1. #1
    Membre éprouvé

    Profil pro
    Account Manager
    Inscrit en
    Décembre 2006
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Account Manager

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 301
    Par défaut PyInstaller, un tuto ?
    Bonjour,
    je suis en train de lire la doc de PyInstaller. Complet mais comme souvent avec les doc. cela manque d'exemples simples concrets.
    Quelqu'un connait-il un tuto vidéo (en anglais ou français) ?

  2. #2
    Membre expérimenté Avatar de alexdevl
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    265
    Détails du profil
    Informations personnelles :
    Âge : 56
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2007
    Messages : 265
    Par défaut
    Bonjour,

    Afin de générer en automatique un exe,

    j'avais fait cette applic pour mon utilisation personelle, mais elle tourne sous wx et je crois que tu est plutot adepte de qt.

    Je post quand même.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
     
    #!/usr/bin/env python
    # -*- coding: iso-8859-1 -*-
    # Version :
    # Pyintasllerg40 Ecriture et récup du fichier ini par ConfigParter,heure de création du .exe
     
    import wx,os,shutil,ConfigParser
    import os,os.path,time
     
    def recup_ini(ficonf,lst_recup):
        #Récupération du fichier de configuration
        #Syntaxe self.lreturn=recup_ini("pyinstallerg40.ini",["fsource","ficone","fpyinstaller","fpythonw"])
        lst_return=[]
        if os.path.exists(ficonf) :
     
            config = ConfigParser.ConfigParser() 
            config.read(ficonf)
            s='local' #Section
            lst_return=[]
            for param in lst_recup :
                lst_return.append(config.get(s, param))
            return lst_return
     
        else : 
            for param in lst_recup :
                lst_return.append('')
            return lst_return
     
    def ecrit_ini(ficonf,lst_param,lst_valeur):
        #Ecriture du fichier de configuration
        #Syntaxe d'appel :
        #ecrit_ini("pyinstallerg40.ini",["fsource","ficone","fpyinstaller","fpythonw"],[fsource,ficone,fpyinstaller,fpythonw])
            config = ConfigParser.ConfigParser()
            s='local' #Section      
            config.add_section(s)
            for i in range(len(lst_param )):
                config.set(s,lst_param[i], lst_valeur[i])
                config.write(open(ficonf,'w'))
            print "ok1"
     
     
     
    #-------------------------------------------
    #         La Frame principale              -
    #-------------------------------------------
    # generated by wxGlade
     
    class MyFrame(wx.Frame):
        def __init__(self, *args, **kwds):
            # begin wxGlade: MyFrame.__init__
            kwds["style"] = wx.DEFAULT_FRAME_STYLE
            wx.Frame.__init__(self, *args, **kwds)
            self.panel_1 = wx.Panel(self, -1)
     
            self.label_01 = wx.StaticText(self.panel_1, -1, "  Nécessite PyInstaller, il est à l'adresse :")
            self.label_02 = wx.StaticText(self.panel_1, -1, "  ")
            self.label_03 = wx.TextCtrl(self.panel_1, -1, "http://pyinstaller.python-hosting.com/",style=wx.TE_READONLY)      
     
            self.label_01.SetForegroundColour(wx.Colour(0, 0, 255))
            self.label_01.SetFont(wx.Font(10, wx.DEFAULT, wx.SLANT, wx.NORMAL, 0, ""))    
     
            self.label_03.SetForegroundColour(wx.Colour(0, 0, 255))
            self.label_03.SetFont(wx.Font(10, wx.DEFAULT, wx.SLANT, wx.NORMAL, 0, ""))    
     
            self.label_1 = wx.StaticText(self.panel_1, -1, "  Fichier source")
            self.button_1 = wx.Button(self.panel_1, -1, "Parcourir")
            self.text_ctrl_1 = wx.TextCtrl(self.panel_1, -1, "")
     
            self.label_2 = wx.StaticText(self.panel_1, -1, "  Fichier icone (Nécessite pywin32)")
            self.button_2 = wx.Button(self.panel_1, -1, "Parcourir")
            self.text_ctrl_2 = wx.TextCtrl(self.panel_1, -1, "")
     
            self.label_4 = wx.StaticText(self.panel_1, -1, "  Emplacement ....pyinstaller-1.3\\configure.py")        
            self.button_4 = wx.Button(self.panel_1, -1, "Parcourir")
            self.text_ctrl_4 = wx.TextCtrl(self.panel_1, -1, "")
     
            self.label_5 = wx.StaticText(self.panel_1, -1, "  Emplacement Pythonw.exe")
            self.button_5 = wx.Button(self.panel_1, -1, "Parcourir")
            self.text_ctrl_5 = wx.TextCtrl(self.panel_1, -1, "")
     
            self.label_6 = wx.StaticText(self.panel_1, -1, "  Effacement des fichiers temporaires")
            self.button_6 = wx.Button(self.panel_1, -1, "Efface !!")
            self.text_ctrl_6 = wx.StaticText(self.panel_1, -1, "")
     
     
            self.label_3 = wx.StaticText(self.panel_1, -1, "  Création .exe")        
            self.button_3 = wx.Button(self.panel_1, -1, "Go !")
            self.text_ctrl_3 = wx.StaticText(self.panel_1, -1, "pyinstallerg")
     
     
            self.__set_properties()
            self.__do_layout()
     
            # Les événements 
     
            self.Bind(wx.EVT_BUTTON, self.parcourir_s, self.button_1) # Boutton Recherche du fichier source
            self.Bind(wx.EVT_BUTTON, self.parcourir_i, self.button_2)  # Boutton Recherche du fichier icone
            self.Bind(wx.EVT_BUTTON, self.parcourir_pyi, self.button_4) # Boutton Recherchedu fichier ....pyinstaller-1.3\Configure.py
            self.Bind(wx.EVT_BUTTON, self.parcourir_pywexe, self.button_5) # Boutton Recherche du fichier pythonw.exe
            self.Bind(wx.EVT_BUTTON, self.bouton_efface, self.button_6)  
     
            self.Bind(wx.EVT_BUTTON, self.go, self.button_3) # Boutton Création du .exe
            self.Bind(wx.EVT_CLOSE, self.onclose) # Quit
     
     
            #---------------------------        
            # Récup de pyinstallerg.ini    -
            #---------------------------
     
            self.lreturn=recup_ini("pyinstallerg40.ini",["fsource","ficone","fpyinstaller","fpythonw"])
            self.text_ctrl_1.SetValue(self.lreturn[0])
            self.text_ctrl_2.SetValue(self.lreturn[1])
            self.text_ctrl_4.SetValue(self.lreturn[2])
            self.text_ctrl_5.SetValue(self.lreturn[3])
            # end wxGlade
     
        def __set_properties(self):
            # begin wxGlade: MyFrame.__set_properties
            self.SetTitle("Pynstallerg")
            self.text_ctrl_1.SetMinSize((500, 24))
            self.text_ctrl_2.SetMinSize((500,24))
            self.label_03.SetMinSize((500,24))
            self.text_ctrl_4.SetMinSize((500,24))
            self.text_ctrl_5.SetMinSize((500,24))
            self.button_1.SetBackgroundColour(wx.Colour(255, 127, 0))
            self.button_3.SetBackgroundColour(wx.Colour(255, 0, 0))
     
     
     
            # end wxGlade
     
        def __do_layout(self):
            # begin wxGlade: MyFrame.__do_layout
            sizer_1 = wx.BoxSizer(wx.VERTICAL)
            grid_sizer_1 = wx.FlexGridSizer(6, 3, 3, 3)
     
     
            grid_sizer_1.Add(self.label_01, 0, 0, 0)
            grid_sizer_1.Add(self.label_02, 0, 0, 0)
            grid_sizer_1.Add(self.label_03, 0, 0, 0)
     
            grid_sizer_1.Add(self.label_1, 0, 0, 0)
            grid_sizer_1.Add(self.button_1, 0, 0, 0)
            grid_sizer_1.Add(self.text_ctrl_1, 0, 0, 0)
     
            grid_sizer_1.Add(self.label_2, 0, 0, 0)
            grid_sizer_1.Add(self.button_2, 0, 0, 0)
            grid_sizer_1.Add(self.text_ctrl_2, 0, 0, 0)
     
            grid_sizer_1.Add(self.label_4, 0, 0, 0)
            grid_sizer_1.Add(self.button_4, 0, 0, 0)
            grid_sizer_1.Add(self.text_ctrl_4, 0, 0, 0)
     
            grid_sizer_1.Add(self.label_5, 0, 0, 0)
            grid_sizer_1.Add(self.button_5, 0, 0, 0)
            grid_sizer_1.Add(self.text_ctrl_5, 0, 0, 0)
     
            grid_sizer_1.Add(self.label_6, 0, 0, 0)
            grid_sizer_1.Add(self.button_6, 0, 0, 0)
            grid_sizer_1.Add(self.text_ctrl_6, 0, 0, 0)
     
            grid_sizer_1.Add(self.label_3, 0, 0, 0)
            grid_sizer_1.Add(self.button_3, 0, 0, 0)
            grid_sizer_1.Add(self.text_ctrl_3, 0, 0, 0)       
     
     
            self.panel_1.SetSizer(grid_sizer_1)
            sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
            self.SetSizer(sizer_1)
            sizer_1.Fit(self)
            self.Layout()
            # end wxGlade
     
        def parcourir_s(self, event): # wxGlade: MyFrame1.<event_handler>
            wildcard = "All files (*.*)|*.*|" \
                "Fichiers textes (*.txt)|*.txt"
            dialog = wx.FileDialog(None, "Choose a file", os.getcwd(), 
                "", wildcard, wx.OPEN)
     
            if dialog.ShowModal() == wx.ID_OK:
                self.text_ctrl_1.SetValue(dialog.GetPath())
            event.Skip()
     
        def parcourir_i(self, event): # wxGlade: MyFrame1.<event_handler>
            wildcard = "All files (*.*)|*.*|" \
                "Fichiers textes (*.txt)|*.txt"
            dialog = wx.FileDialog(None, "Choose a file", os.getcwd(), 
                "", wildcard, wx.OPEN)
     
            if dialog.ShowModal() == wx.ID_OK:
                self.text_ctrl_2.SetValue(dialog.GetPath())
            event.Skip()
     
        def parcourir_pyi(self, event): # wxGlade: MyFrame1.<event_handler>
            wildcard = "All files (*.*)|*.*|" \
                "Fichiers textes (*.txt)|*.txt"
            dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),
                "", wildcard, wx.OPEN)
     
            if dialog.ShowModal() == wx.ID_OK:
                self.text_ctrl_4.SetValue(dialog.GetPath())
            event.Skip()
     
     
        def parcourir_pywexe(self, event): # wxGlade: MyFrame1.<event_handler>
            wildcard = "All files (*.*)|*.*|" \
                "Fichiers textes (*.txt)|*.txt"
            dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),
                "", wildcard, wx.OPEN)
     
            if dialog.ShowModal() == wx.ID_OK:
                self.text_ctrl_5.SetValue(dialog.GetPath())
     
     
        def bouton_efface(self, event): # wxGlade: MyFrame1.<event_handler>       
            fsource=self.text_ctrl_1.GetValue()
            ficone=self.text_ctrl_2.GetValue()
            cheminpyi=self.text_ctrl_4.GetValue()
            cheminpywexe=self.text_ctrl_5.GetValue()      
     
            fsansfin=fsource[:len(fsource)-3]
            if fsource[len(fsource)-3:]=="pyw": fsansfin=fsource[:len(fsource)-4]
     
            fseul=fsansfin.split(os.sep) # Sans les /
            frep=os.sep.join(fseul[:len(fseul)-1])+os.sep # Rep du fichier source
            fwarn=frep+"warn"+fseul[len(fseul)-1]+".txt"
            fbuild=frep+"build"+fseul[len(fseul)-1]+os.sep        
     
            bilan_eff="Ont été effacés : "
     
            if os.path.exists(fsansfin+".bat") :
                os.remove(fsansfin+".bat")
                bilan_eff+="  .bat"
     
            if os.path.exists(fsansfin+".spec") :
                os.remove(fsansfin+".spec")
                bilan_eff+="  .spec"
     
            if os.path.exists(fwarn) :
                os.remove(fwarn)
                bilan_eff+="  warnX.txt"
     
            if os.path.exists(fbuild) :
                shutil.rmtree(fbuild)
                bilan_eff+="  buildX\\"        
     
     
            self.text_ctrl_6.SetLabel(bilan_eff) 
     
     
     
    #-----------------------------------------------------
    #   Go = > Création du fihier                        -
    #-----------------------------------------------------
     
        def go(self, event): # wxGlade: MyFrame1.<event_handler>
            fsource=self.text_ctrl_1.GetValue()
            ficone=self.text_ctrl_2.GetValue()
            cheminpyi=self.text_ctrl_4.GetValue()
            cheminpywexe=self.text_ctrl_5.GetValue()
     
     
     
            fsansfin=fsource[:len(fsource)-3]
            if fsource[len(fsource)-3:]=="pyw": fsansfin=fsource[:len(fsource)-4]
     
            fseul=fsansfin.split(os.sep) # sans slash
            frep=os.sep.join(fseul[:len(fseul)-1])+os.sep
     
            chempyiseul=cheminpyi.split(os.sep)
            reppyi=os.sep.join(chempyiseul[:len(chempyiseul)-1])+os.sep
     
     
             #Création du nouveau fichier
            os.chdir(frep) #mettre le bon rep
            fichierobjetsortie=open(fsansfin+".bat",'w')
            fichierobjetsortie.write(cheminpywexe+" "+reppyi+os.sep+"configure.py"+'\n')
            if ficone!="" :
                fichierobjetsortie.write(cheminpywexe+" "+reppyi+'Makespec.py -F -w --icon='+ficone+' "'+fsource+'"'+'\n')
            else:
                fichierobjetsortie.write(cheminpywexe+" "+reppyi+'Makespec.py -F -w "'+fsource+'"'+'\n')
     
            fichierobjetsortie.write(cheminpywexe+" "+reppyi+"build.py "+fsansfin+'.spec'+'\n')
            fichierobjetsortie.close()       
     
            os.system(fsansfin+".bat")
            self.text_ctrl_3.SetLabel("")               
            if fsource!="" and os.path.exists(fsansfin+".exe") :
                os.system(fsansfin+".bat")     
                self.text_ctrl_3.SetLabel(" Creation OK ! "+fsansfin+".exe : "+time.strftime('%H:%M:%S'))
            event.Skip()
     
     
    #-----------------------------------------------------
    #   Quit => sauvegarde dans pyinstallerg.ini         -
    #-----------------------------------------------------
     
     
        def onclose(self,event):
            #try :
            if os.path.exists('pyinstallerg40.ini') : os.remove('pyinstallerg40.ini')
            fsource=self.text_ctrl_1.GetValue()
            ficone=self.text_ctrl_2.GetValue()
            fpyinstaller=self.text_ctrl_4.GetValue()
            fpythonw=self.text_ctrl_5.GetValue()
     
            ecrit_ini("pyinstallerg40.ini",["fsource","ficone","fpyinstaller","fpythonw"],[fsource,ficone,fpyinstaller,fpythonw])
            self.Destroy()
     
    # end of class MyFrame
     
     
    if __name__ == "__main__":
        app = wx.PySimpleApp(0)
        wx.InitAllImageHandlers()
        frame_1 = MyFrame(None, -1, "")
        app.SetTopWindow(frame_1)
        frame_1.Show()
        app.MainLoop()
    Alex

  3. #3
    Membre éprouvé

    Profil pro
    Account Manager
    Inscrit en
    Décembre 2006
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Account Manager

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 301
    Par défaut
    Merci ton interface est simple donc bien pour débuter.

    Je vais regarder cela en détail. Je vais sûrement faire une version PyQt avec peut-être la gestion de certaines options mais de ce côté pour l'instant je ne maîtrise rien.

Discussions similaires

  1. Un tuto pour direct show
    Par Olivier Delmotte dans le forum DirectX
    Réponses: 11
    Dernier message: 04/04/2003, 22h28
  2. tuto sur MDI
    Par nicholz dans le forum Composants VCL
    Réponses: 2
    Dernier message: 25/01/2003, 18h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo