Problème avec pyinstaller

Résolu
Python -  
mamiemando Messages postés 33772 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,

J'ai fait un script python (de test) et j'aimerais bien le mettre en exécutable (pour tester encore une fois) donc j'installe le module pyinstaller correctement. je vais dans mon fichier test, puis j'éxécute avec
cmd
. Je fais
pyinstaller test.py
et ça ne fonctionne pas voici le message d'erreur :

C:\Users\maxmo\OneDrive\Bureau\test>pyinstaller test.py
90 INFO: PyInstaller: 4.4
90 INFO: Python: 3.9.5
146 INFO: Platform: Windows-10-10.0.19042-SP0
151 INFO: wrote C:\Users\maxmo\OneDrive\Bureau\test\test.spec
154 INFO: UPX is not available.
156 INFO: Extending PYTHONPATH with paths
['C:\\Users\\maxmo\\OneDrive\\Bureau\\test',
'C:\\Users\\maxmo\\OneDrive\\Bureau\\test']
Traceback (most recent call last):
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\maxmo\AppData\Local\Programs\Python\Python39-32\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\site-packages\PyInstaller\__main__.py", line 126, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\site-packages\PyInstaller\building\build_main.py", line 758, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\site-packages\PyInstaller\building\build_main.py", line 705, in build
exec(code, spec_namespace)
File "C:\Users\maxmo\OneDrive\Bureau\test\test.spec", line 7, in <module>
a = Analysis(['test.py'],
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\site-packages\PyInstaller\building\build_main.py", line 220, in __init__
self.hookspath += list(entry_point.load()())
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\site-packages\pkg_resources\__init__.py", line 2450, in load
return self.resolve()
File "c:\users\maxmo\appdata\local\programs\python\python39-32\lib\site-packages\pkg_resources\__init__.py", line 2456, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "C:\Users\maxmo\AppData\Roaming\Python\Python39\site-packages\pygame\__init__.py", line 81, in <module>
from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ModuleNotFoundError: No module named 'pygame.base'


et voici mon script du fichier
test.py
:

import game
import tkinter

def open():
    game.run()


app = tkinter.Tk()
app.title("Mon app tkinter")
app.geometry("300x100")

lb = tkinter.Label(app, text="Cliquer sur le bouton...").pack()
bt = tkinter.Button(app, text="Hack tkinter", command=open).pack()

app.mainloop()


et du fichier
game.py
:

import pygame

def run():
    pygame.init()

    screen = pygame.display.set_mode([400, 400])

    launched = True
    while launched:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                launched = False

        screen.fill((12, 25, 38))
        pygame.draw.line(screen, (128, 25, 240), [10, 10], [280, 310], 3)
        pygame.display.flip()

    pygame.quit()


Merci de m'aider.
A voir également:

3 réponses

mamiemando Messages postés 33772 Date d'inscription   Statut Modérateur Dernière intervention   7 882
 
Bonjour,

Ton erreur n'est pas lié à ton code lui-même, mais à la manière dont tu utilises
pyinstaller
.
  • Assure-toi que le
    pygame
    est bien installé (par exemple en lançant ton code python normalement) ;
  • Regarde cette page pour avoir davantage d'information de debug et au besoin précise le chemin vers pygame avec l'option
    --paths
    ;
  • Regarde cette page pour l'option
    --hidden-import
    et au besoin passe par un venv (voir message #14) ;


Bonne chance
1
Python_2522
 
Merci ça a marché !
0
mamiemando Messages postés 33772 Date d'inscription   Statut Modérateur Dernière intervention   7 882 > Python_2522
 
Parfait, je bascule ton sujet en résolu :-)
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Bonjour,

L'indentation étant importante en Python, merci de copier/coller ici ton code complet avec les balises de code
mode d'emploi:
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Visuellement, ça doit ressembler à ceci (avec la coloration syntaxique) :

def test():
    print('test')

test()
0
Python_2522 Messages postés 9 Date d'inscription   Statut Membre Dernière intervention  
 

le fichier test.py : 
import game
import tkinter


def open():
    game.run()


app = tkinter.Tk()
app.title("Test")
app.geometry("300x100")

lb = tkinter.Label(app, text="Cliquer sur le bouton...").pack()
bt = tkinter.Button(app, text="Test", command=open).pack()

app.mainloop()



le fichier game.py : 

import pygame


def run():
    pygame.init()

    screen = pygame.display.set_mode([400, 400])

    launched = True
    while launched:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                launched = False

        screen.fill((12, 25, 38))
        pygame.draw.line(screen, (128, 25, 240), [10, 10], [280, 310], 3)
        pygame.display.flip()

    pygame.quit()

0