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

Déploiement/Installation Python Discussion :

Probleme déploiement application avec qtpy


Sujet :

Déploiement/Installation Python

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 226
    Points : 39
    Points
    39
    Par défaut Probleme déploiement application avec qtpy
    Bonjour,
    j'ai récemment développé une application avec python et QT.

    Voici mon application

    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
    import os
    import urllib.request, json
    import sys
    import math
    from PySide2.QtWidgets import QApplication, QLabel, QProgressBar, QWidget, QTextEdit, QPushButton
    from PySide2 import *
    from time import sleep
     
    def getFile(path):
        return  [os.path.join(r,file) for r,d,f in os.walk(path) for file in f]
     
    def updateSizePython(files):
        for i in range(len(files)):
            statinfo = os.stat(files[i])
            files[i] =  files[i].replace('./', '')
            files[i] =  files[i].replace('\\', '/')
            files[i] = [files[i], statinfo.st_size]
        return files
     
     
    def getDataDiff():
        with urllib.request.urlopen("http://update.serviceonline.fr") as url:
            data = json.loads(url.read().decode())
        return (data)
     
    def downloadfile(file, progressBar, pourcent, textarea):
        oldText = textarea.toPlainText()
        #print('http://update.serviceonline.fr/' +  file[0])
        textarea.setPlainText(oldText + "[+] Téléchargement du fichier  " +  file[0] + "\n" )
        oldText = textarea.toPlainText()
        url = 'http://update.serviceonline.fr/' + file[0]
        path = "./"
        dir = file[0].split("/")
        del dir[len(dir) - 1]
        for pathcut in dir:
            path = path + pathcut + "/"
        if os.path.isdir(path) == False:
            textarea.setPlainText(oldText + "[+] Création du dossier " + path + "\n" )
            os.makedirs(path)
        oldText = textarea.toPlainText()
        try:
            urllib.request.urlretrieve(url, './' + file[0])
            add = progressBar.value() + pourcent
            if progressBar.value() + pourcent >= 100:
                add = 100
            progressBar.setProperty("value", add)
            textarea.setPlainText(oldText + "[+] Décompression du fichier " + file[0] + "\n")
     
        except FileNotFoundError:
            textarea.setPlainText(oldText + "[+] Erreur lors de la décompression du fichier " + file[0] + "\n")
     
    def start():
        os.startfile("serviceOnline.exe")
        sys.exit(0)
     
    def runUpdate():
        #sleep(1)
        #print("Update serviceonline")
        files = getFile("./")
        files = updateSizePython(files)
        textarea.setPlainText("[+] Téléchargement de l'index \n")
        dataremote = getDataDiff()
        diff = lambda l1,l2: [x for x in l1 if x not in l2]
     
        #à DL = diff(dataremote,files)
        #a remove = diff(files, dataremote)
        download = diff(dataremote,files)
     
     
        nbDownload = len(download)
        if nbDownload == 0:
            oldText = textarea.toPlainText()
            textarea.setPlainText( oldText + "[+] serviceonline est à jour \n")
            progressBar.setProperty("value", 100)
        else:
            for i in range(len(download)):
                #print (download[i])
                downloadfile(download[i], progressBar, math.ceil(100 / nbDownload), textarea)
        btnStart.setVisible(True)
     
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        windows = QWidget()
        windows.setFixedSize(450, 400)
        progressBar = QProgressBar(windows)
        progressBar.setGeometry(20, 10, 400, 23)
        progressBar.setProperty("value", 0)
        progressBar.setTextVisible(False)
        progressBar.setObjectName("progressBar")
        windows.setWindowTitle("Update serviceOnline")
        textarea = QTextEdit(windows)
        textarea.move(20,50)
        textarea.setMinimumSize(400,100)
        textarea.setReadOnly(1)
        btnStart = QPushButton('Lancer serviceonline',windows)
        btnStart.setVisible(False)
        btnStart.move(20,260)
        btnStart.connect(btnStart, QtCore.SIGNAL('clicked()'), start)
        windows.show()
     
     
        QtCore.QTimer.singleShot(500, runUpdate)
        sys.exit(app.exec_())
    J'aimerai faire une application compilé et j'ai vu que c'etait possible avec pyinstaller

    j'ai donc exécuté la commande suivante

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    pyinstaller --paths="C:\Users\baptiste\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\shiboken2" --paths="C:\Users\baptiste\AppData\Local\Programs\P
    ython\Python37-32\Lib\site-packages\PySide2" --name="TestApp" --onedir --windowed --noconsole .\update.py
    Quand je souhaite lancé mon update.exe , la console souvre quelques secondes et se ferme ... impossible de lire l'erreur (en double cliquant dessous ou l'executant avec CMD)


    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
    raceback:
    Pyinstaller --paths="C:\Users\baptiste\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\shiboken2" --paths="C:\Users\baptiste\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PySide2" .\update.py
    45 INFO: PyInstaller: 3.5.dev0+cb8d10af6
    45 INFO: Python: 3.7.2
    45 INFO: Platform: Windows-10-10.0.17763-SP0
    46 INFO: wrote D:\ProjetUpdater\update.spec
    48 INFO: UPX is not available.
    49 INFO: Extending PYTHONPATH with paths
    ['D:\ProjetUpdater',
    'C:\Users\baptiste\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\shiboken2',
    'C:\Users\baptiste\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PySide2',
    'D:\ProjetUpdater']
    49 INFO: checking Analysis
    49 INFO: Building Analysis because Analysis-00.toc is non existent
    50 INFO: Initializing module dependency graph...
    52 INFO: Initializing module graph hooks...
    54 INFO: Analyzing base_library.zip ...
    2720 INFO: running Analysis Analysis-00.toc
    2722 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
    required by c:\users\baptiste\appdata\local\programs\python\python37-32\python.exe
    3801 INFO: Caching module hooks...
    13704 INFO: Analyzing D:\ProjetUpdater\update.py
    13892 INFO: Loading module hooks...
    13892 INFO: Loading module hook "hook-encodings.py"...
    13962 INFO: Loading module hook "hook-pydoc.py"...
    13963 INFO: Loading module hook "hook-PySide2.py"...
    13964 WARNING: Hidden import "numpy.core.multiarray" not found!
    13965 INFO: Loading module hook "hook-PySide2.QtNetwork.py"...
    14064 INFO: Loading module hook "hook-PySide2.QtWidgets.py"...
    14065 INFO: Loading module hook "hook-xml.py"...
    14113 INFO: Loading module hook "hook-PySide2.QtCore.py"...
    14188 INFO: Loading module hook "hook-PySide2.QtGui.py"...
    14722 INFO: Looking for ctypes DLLs
    14722 INFO: Analyzing run-time hooks ...
    14726 INFO: Including run-time hook 'pyi_rth_qt5plugins.py'
    14731 INFO: Looking for dynamic libraries
    24710 INFO: Looking for eggs
    24711 INFO: Using Python library c:\users\baptiste\appdata\local\programs\python\python37-32\python37.dll
    24712 INFO: Found binding redirects:
    []
    24722 INFO: Warnings written to D:\ProjetUpdater\build\update\warn-update.txt
    24759 INFO: Graph cross-reference written to D:\ProjetUpdater\build\update\xref-update.html
    24780 INFO: checking PYZ
    24780 INFO: Building PYZ because PYZ-00.toc is non existent
    24782 INFO: Building PYZ (ZlibArchive) D:\ProjetUpdater\build\update\PYZ-00.pyz
    25316 INFO: Building PYZ (ZlibArchive) D:\ProjetUpdater\build\update\PYZ-00.pyz completed successfully.
    25330 INFO: checking PKG
    25330 INFO: Building PKG because PKG-00.toc is non existent
    25330 INFO: Building PKG (CArchive) PKG-00.pkg
    25345 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
    25347 INFO: Bootloader c:\users\baptiste\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
    25347 INFO: checking EXE
    25349 INFO: Building EXE because EXE-00.toc is non existent
    25350 INFO: Building EXE from EXE-00.toc
    25351 INFO: Appending archive to EXE D:\ProjetUpdater\build\update\update.exe
    25408 INFO: Building EXE from EXE-00.toc completed successfully.
    25415 INFO: checking COLLECT
    25415 INFO: Building COLLECT because COLLECT-00.toc is non existent
    25415 INFO: Building COLLECT COLLECT-00.toc
    26199 INFO: Building COLLECT COLLECT-00.toc completed successfully.
    PS D:\ProjetUpdater>
    Pouvez vous m'aider ? c'est la premiere fois que je fait une compilation d'un programme python

  2. #2
    Expert éminent
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 461
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 461
    Points : 9 248
    Points
    9 248
    Billets dans le blog
    6
    Par défaut
    Bonjour,

    Dans l'exécution normale (sans traitement par pyinstaller), j'ai l'erreur suivante (Python 3.7.1, PySide2):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Traceback (most recent call last):
      File "C:/Pythondev/python3/tests/test01.py", line 63, in runUpdate
        dataremote = getDataDiff()
      File "C:/Pythondev/python3/tests/test01.py", line 24, in getDataDiff
        data = json.loads(url.read())#.decode())
      File "C:\Python37\lib\json\__init__.py", line 348, in loads
        return _default_decoder.decode(s)
      File "C:\Python37\lib\json\decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "C:\Python37\lib\json\decoder.py", line 355, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    Est-ce qu'il me manque quelque chose?
    Un expert est une personne qui a fait toutes les erreurs qui peuvent être faites, dans un domaine étroit... (Niels Bohr)
    Mes recettes python: http://www.jpvweb.com

  3. #3
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 298
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 298
    Points : 6 778
    Points
    6 778
    Par défaut
    Salut,

    Cette url retourne une page html, pas un contenu au format json.

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 226
    Points : 39
    Points
    39
    Par défaut
    La bonne url est la suivante : http://update.sevenonline.fr/.

    le programme fonctionne avec cette URL , cependant il ne fonctionne pas une fois compilé en exe. je vois juste la console s'ouvrir et se fermer sans avoir le temps de faire quelque chose.

  5. #5
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 298
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 298
    Points : 6 778
    Points
    6 778
    Par défaut
    Ben, plutôt que de double-cliquer sur ton exe, ouvre une console et lance-le à partir de là.

    La console ne se fermera pas en cas d'erreur.

    Edit:
    Au fait, l'url est ok maintenant.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    >>> with urllib.request.urlopen("http://update.sevenonline.fr") as url:
    ...     content = url.read()
    ... 
    >>> data = json.loads(content)
    >>> data[:5]
    [['pack/outdoorb2.epk', 3560180], ['pack/outdoorguild2.epk', 209512], ['pack/property.epk', 370176], ['pack/item.eix', 57264], ['pack/root.eix', 2856]]

  6. #6
    Expert éminent
    Avatar de tyrtamos
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2007
    Messages
    4 461
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2007
    Messages : 4 461
    Points : 9 248
    Points
    9 248
    Billets dans le blog
    6
    Par défaut
    Bonjour,

    Désolé, mais je n'arrive pas à faire fonctionner correctement ce programme (avant le traitement pyinstaller).

    Au lancement, la fenêtre s'affiche. D'après le code, je devrais avoir un QPushButton, mais je ne vois pas. Le téléchargement commence tout de suite, mais il est TRES long (1h? 2h?), et pendant tout ce temps, le graphique est figé, sauf la barre de progression et l'affichage des lignes du déroulement. On ne peut donc pas arrêter le téléchargement sans faire crasher le programme. Il faut mettre les téléchargements dans un thread.

    J'ai voulu vérifier que pyinstaller marchait bien avec PySide2: j'ai donc essayé avec un programme PySide2 mini (une simple fenêtre QWidget), et... ça marche très bien.

    J'ai ensuite essayé pyinstaller avec ton programme (et le bon url), et je trouve la même chose que toi: "Failed to execute script ". Si je lance l'exe dans une console, il ne mentionne aucune erreur.

    Je pense qu'il faut d'abord améliorer le code du programme avant d'utiliser pyinstaller.

    Par exemple:
    - ne pas créer une nouvelle variable appelée "dir" parce que c'est déjà utilisé par Python (=> essaie dir() en console Python).
    - éviter les importations "attrape tout" ("*") => "from PySide2 import QtCore"
    - créer une classe héritant de QWidget pour porter tout ce qu'il y a dans la fenêtre graphique. On utilise QGridLayout pour positionner les widgets dans la fenêtre.
    - mettre le téléchargement dans un QThread pour ne pas geler le graphique (la progression est transmise par signal)
    - etc...
    Un expert est une personne qui a fait toutes les erreurs qui peuvent être faites, dans un domaine étroit... (Niels Bohr)
    Mes recettes python: http://www.jpvweb.com

Discussions similaires

  1. Déploiement application avec PHP
    Par DBA_OCP dans le forum Flex
    Réponses: 19
    Dernier message: 11/02/2011, 15h48
  2. [Déploiement]Application avec BDD
    Par atar64 dans le forum Général Dotnet
    Réponses: 0
    Dernier message: 14/04/2009, 17h23
  3. Déploiement application avec MySQL
    Par Roy Miro dans le forum JDBC
    Réponses: 23
    Dernier message: 30/05/2007, 12h31
  4. Réponses: 1
    Dernier message: 12/01/2007, 16h56

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