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

Python Discussion :

pyinstaller et fichier csv


Sujet :

Python

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Enseignant
    Inscrit en
    Octobre 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2020
    Messages : 32
    Points : 25
    Points
    25
    Par défaut pyinstaller et fichier csv
    Bonjour, je voudrais créer un fichier exécutable à partir d'un programme python de gestion de contact (nom et n° de tél) qui stocke les données dans un fichier csv.

    Quand j'utilise la commande pyinstaller, j'obtiens cette exception:

    Exception: Unable to access file 'C:\Users\nadch\Scripts\Contact\build\Contact\Contact.exe': [Errno 22] Invalid argument: 'C:\\Users\\nadch\\Scripts\\Contact\\build\\Contact\\Contact.exe'
    Voici le programme:
    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
    import csv
    import os
     
    def load_file(file):
     
        infile=open(file,'r',newline='')
        Header=["Name","Phone"]
        contact=[]
        i=0
        index=1
        print()
        print("{0:^25} {1:^22}".format(Header[0],Header[1]))
        print()
        for row in csv.reader(infile):
            contact.append(row)
            name=contact[i][0]
            phone=contact[i][1]
            print("{0:<1})   {1:<18}   {2:^20}".format(index,name,phone))
            i=i+1
            index=index+1
        print()
     
     
        infile.close()
     
    def create(file):
        infileA=open(file,'a',newline='')
        name=input("Enter new name: ")
        phone=input("Enter new number: ")
        contact=[name,phone]
        csv.writer(infileA).writerow(contact)
        infileA.close()
        print("Done.")
        print()
     
    def edit(file):
        contact=[]
        infileR=open(file,'r',newline='')
     
        nmbC=0
        for row in csv.reader(infileR):
            contact.append(row)
            nmbC=nmbC+1
     
        choice=int(input("Which contact would you like to edit (enter index)? "))    
        while 1>choice or choice>len(contact): 
            print()
            print("Index out of range")
            print()
            choice=int(input("Which contact would you like to edit (enter index)? "))
        contact[choice-1][0]=input("Enter new name ")
        contact[choice-1][1]=input("Enter new number ")
     
        infileW=open(file,'w',newline='')
        for row in contact:
            csv.writer(infileW).writerow(row)
        infileR.close()
        infileW.close()
        print("Done.")
        print()
     
     
    def reorder(file):
        contact=[]
        infileR=open(file,'r',newline='')
     
        for row in csv.reader(infileR):
            contact.append(row)
     
        contact.sort()                
     
        infileW=open(file,'w',newline='')
        for row in contact:
            csv.writer(infileW).writerow(row)
        infileR.close()
        infileW.close()
     
    def delete(file):
        contact=[]
        infileR=open(file,'r',newline='')
     
        nmbC=0
        for row in csv.reader(infileR):
            contact.append(row)
            nmbC=nmbC+1
     
        choice=int(input("Which contact would you like to delete (enter index)? "))    
        while 1>choice or choice>len(contact): 
            print()
            print("Index out of range")
            print()
            choice=int(input("Which contact would you like to delete (enter index)? "))
        contact.remove(contact[choice-1])
     
        infileW=open(file,'w',newline='')
        for row in contact:
            csv.writer(infileW).writerow(row)    
     
    def choices():
     
        print("What do you want to do ? ")
        print("1) s: show")
        print("2) c: create")
        print("3) e: edit")
        print("4) d: delete")
        print("5) q: quit")
        print("6) r: reorder")
        choice=input("Type here the letter corresponding to your choice: ")
        if choice not in ['s','S','c','C','e','E','d','D','q','Q','r','R']:
            print("Invalid choice")
        else:
            return choice.lower()
     
    def Contact(filename):
        file=filename
        load_file(file)
        while True:
            choice=choices()
            if choice=='s':
                load_file(file)
            elif choice=='c':
                create(file)
            elif choice=='e':
                edit(file)
            elif choice=='d':
                delete(file)
            elif choice=='r':
                reorder(file)
            elif choice=='q':
                print("Exiting...")
                break
    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
    C:\Users\nadch\Scripts\Contact>pyinstaller Contact.py
    65 INFO: PyInstaller: 4.3
    65 INFO: Python: 3.9.2
    65 INFO: Platform: Windows-10-10.0.18362-SP0
    92 INFO: wrote C:\Users\nadch\Scripts\Contact\Contact.spec
    95 INFO: UPX is not available.
    96 INFO: Extending PYTHONPATH with paths
    ['C:\\Users\\nadch\\Scripts\\Contact', 'C:\\Users\\nadch\\Scripts\\Contact']
    106 INFO: checking Analysis
    130 INFO: checking PYZ
    147 INFO: checking PKG
    148 INFO: Building because C:\Users\nadch\Scripts\Contact\build\Contact\Contact.exe.manifest changed
    148 INFO: Building PKG (CArchive) PKG-00.pkg
    164 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
    165 INFO: Bootloader c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
    165 INFO: checking EXE
    166 INFO: Building EXE because EXE-00.toc is non existent
    166 INFO: Building EXE from EXE-00.toc
    167 INFO: Copying icons from ['c:\\users\\nadch\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
    195 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
    196 INFO: Writing RT_ICON 1 resource with 3752 bytes
    196 INFO: Writing RT_ICON 2 resource with 2216 bytes
    196 INFO: Writing RT_ICON 3 resource with 1384 bytes
    196 INFO: Writing RT_ICON 4 resource with 37019 bytes
    197 INFO: Writing RT_ICON 5 resource with 9640 bytes
    197 INFO: Writing RT_ICON 6 resource with 4264 bytes
    198 INFO: Writing RT_ICON 7 resource with 1128 bytes
    202 INFO: Appending archive to EXE C:\Users\nadch\Scripts\Contact\build\Contact\Contact.exe
    Traceback (most recent call last):
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\pefile.py", line 1802, in __parse__
        fd = open(fname, 'rb')
    OSError: [Errno 22] Invalid argument: 'C:\\Users\\nadch\\Scripts\\Contact\\build\\Contact\\Contact.exe'
     
    During handling of the above exception, another exception occurred:
     
    Traceback (most recent call last):
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Users\nadch\AppData\Local\Programs\Python\Python39\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 114, in run
        run_build(pyi_config, spec_file, **vars(args))
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
        PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 737, in main
        build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 684, in build
        exec(code, spec_namespace)
      File "C:\Users\nadch\Scripts\Contact\Contact.spec", line 21, in <module>
        exe = EXE(pyz,
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\api.py", line 450, in __init__
        self.__postinit__()
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
        self.assemble()
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\api.py", line 645, in assemble
        set_exe_checksum(self.name)
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\win32\winutils.py", line 168, in set_exe_checksum
        pe = pefile.PE(exe_path)
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\pefile.py", line 1754, in __init__
        self.__parse__(name, data, fast_load)
      File "c:\users\nadch\appdata\local\programs\python\python39\lib\site-packages\pefile.py", line 1814, in __parse__
        raise Exception('Unable to access file \'{0}\'{1}'.format(fname, exception_msg))
    Exception: Unable to access file 'C:\Users\nadch\Scripts\Contact\build\Contact\Contact.exe': [Errno 22] Invalid argument: 'C:\\Users\\nadch\\Scripts\\Contact\\build\\Contact\\Contact.exe'
    Comment est-ce que je pourrais régler le problème?
    Merci!
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 283
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 283
    Points : 36 770
    Points
    36 770
    Par défaut
    Salut,

    Essayez avec la commande pyinstaller --clean Contact.py

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Enseignant
    Inscrit en
    Octobre 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2020
    Messages : 32
    Points : 25
    Points
    25
    Par défaut
    Merci de répondre. J'ai essayé mais j'obtiens toujours la même erreur.

  4. #4
    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,

    Je viens d'essayer (Windows 10, Python 3.7, pyinstaller 4.2): téléchargement du "contact.py" en pièce jointe, et "pyinstaller contact.py" en console: aucun problème!

    L'exécution de "contact.exe" du sous-répertoire "dist" en console (pour avoir les éventuelles erreurs) ne pose aucun problème non plus, mais il n'y a pas vraiment d'exécution hors des fonctions déclarées.

    J'ai passé le code de "contact.y" avec l'analyseur de code "pylint": pas de problème non plus (à part l'importation de "os" non utilisée).

    => il y a donc très probablement soit un problème d'installation, soit un problème de version.
    - Pour tester le problème d'installation, on peut tester pyinstaller avec un code Python simple du genre print("Coucou!").
    - Pour les problèmes de versions: j'ai toujours un léger retard volontaire dans l'utilisation des nouvelles versions de Python, à cause des retards courants des modules externes qui m'intéressent, et j'évite ainsi en plus d'éventuels problèmes de jeunesse de la nouvelle version. Actuellement, je suis toujours avec Python 3.7, et Python 3.8 est suffisant, sauf si on veut vraiment utiliser les nouveautés de la version 3.9.
    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

  5. #5
    Nouveau membre du Club
    Femme Profil pro
    Enseignant
    Inscrit en
    Octobre 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2020
    Messages : 32
    Points : 25
    Points
    25
    Par défaut
    Bnjour, merci!

    Vous pourriez me donner les versions que vous avez utilisé? J'ai désinstallé Python 3.9 et réinstallé 3.8. Toujours le même résultat.

  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
    Citation Envoyé par Nadia Teach Voir le message
    Vous pourriez me donner les versions que vous avez utilisé?
    Je les ai déjà données: Windows 10, Python 3.7, pyinstaller 4.2.

    Je viens d'installer Python 3.8.9 avec pyinstaller 4.3 sur mon portable, et j'ai la même erreur que vous!

    J'ai essayé avec un code simplissime type print("coucou"), et la même erreur se produit. Ce n'est donc pas votre code qui fait l'erreur.

    J'ai essayé en mode administrateur: c'est pareil.

    Je cherche...
    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

  7. #7
    Nouveau membre du Club
    Femme Profil pro
    Enseignant
    Inscrit en
    Octobre 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2020
    Messages : 32
    Points : 25
    Points
    25
    Par défaut
    Merci beaucoup, j'ai rétrogradé à la version 3.7. J'ai obtenu un fichier exécutable mais rien ne se passe. Une fenêtre apparaît et disparait aussitôt.

  8. #8
    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
    Citation Envoyé par Nadia Teach Voir le message
    Merci beaucoup, j'ai rétrogradé à la version 3.7. J'ai obtenu un fichier exécutable mais rien ne se passe. Une fenêtre apparaît et disparait aussitôt.
    Si c'est avec le fichier "contact.py", c'est normal: il n'y a que des fonctions mais aucun appel!
    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

  9. #9
    Nouveau membre du Club
    Femme Profil pro
    Enseignant
    Inscrit en
    Octobre 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2020
    Messages : 32
    Points : 25
    Points
    25
    Par défaut
    D'accord, merci!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ajout de fichiers CSV avec pyinstaller
    Par Julienbot dans le forum Déploiement/Installation
    Réponses: 0
    Dernier message: 26/06/2015, 17h24
  2. Mise à jour d'une table avec un fichier csv
    Par blackangel dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 26/05/2005, 14h46
  3. Mettre a jour BD avec fichier csv
    Par Looping94510 dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 07/02/2005, 18h56
  4. Sortir un fichier csv sur base d une requete
    Par Freeman_80 dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 12/01/2005, 11h21
  5. Réponses: 2
    Dernier message: 14/05/2004, 12h55

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