0

I created a main.exe file by using python pyinstaller with this command line

pyinstaller main.py --onefile 

Then, if I run the main.exe file it just blinks and then disappears. Running the .exe from command line generates this error.

[INFO   ] [Logger      ] Record log in C:\Users\davide.tamagnini.con\.kivy\logs\kivy_21-07-05_84.txt
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "C:\Users\DAVIDE~1.CON\AppData\Local\Temp\_MEI78722\kivy\__init__.pyc"
[INFO   ] [Python      ] v3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\davide.tamagnini.con\Desktop\kivy-Galaxy\main.exe"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.0 - Build 27.20.100.8337'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics 620'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60 - Build 27.20.100.8337'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[WARNING] [Image       ] Unable to load image <C:\Users\DAVIDE~1.CON\AppData\Local\Temp\_MEI78722\kivy_install\data\glsl\default.png>
[CRITICAL] [Window      ] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - Exception: SDL2: Unable to load image
  File "kivy\core\__init__.py", line 70, in core_select_lib
  File "kivy\core\window\window_sdl2.py", line 152, in __init__
  File "kivy\core\window\__init__.py", line 982, in __init__
  File "kivy\core\window\window_sdl2.py", line 311, in create_window
  File "kivy\core\window\__init__.py", line 1268, in create_window
  File "kivy\graphics\instructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
  File "kivy\core\image\__init__.py", line 561, in __init__
  File "kivy\core\image\__init__.py", line 754, in _set_filename
  File "kivy\core\image\__init__.py", line 460, in load
  File "kivy\core\image\__init__.py", line 223, in __init__
  File "kivy\core\image\img_sdl2.py", line 47, in load

[INFO   ] [Audio       ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
[CRITICAL] [App         ] Unable to get a Window, abort.

This file should execute a small game with user interaction. I put the main.exe file in the same directory where all the dependencies are contained.

If I run the main.py file using PyCharm everything works well.

Did anyone face the same problem?

MegaIng
  • 7,361
  • 1
  • 22
  • 35

1 Answers1

1

For using pyinstallr its not straight forward to make a build .

I will give you an example of the build.

you would have to have this .spec for building.

You have to give pyinstaller all the different types of files it has to fetch and how to organize them . You have an example below

datas=[('F:\path\to\proj\*.kv', '.' )

  (  'path in you local'                ,  'root dir for exe')

Use "*.png / *.kv " to fetch all the files.

PLEASE VISIT HERE AND SEE WHAT OTHER IMPORTS YOU MIGHT NEED.

Click HERE

# -*- mode: python ; coding: utf-8 -*-
import sys
import os
from kivymd import hooks_path as kivymd_hooks_path
from kivy_deps import sdl2, glew
path = os.path.abspath(".")

block_cipher = None

a = Analysis(['F:\\path\\to\\projectdir\\main.py'],
             pathex=['F:\\path\\to\\projectdir'],
             binaries=[],
             datas=[('F:\\path\\to\\projectdir\\data','.'),
('F:\\path\\to\\projectdir\\images\\*.png','.\\images'),
('F:\\path\\to\\projectdir\\data\\*.ico','.\\images'),
('F:\\path\\to\\projectdir\\*.ico','.'),
('F:\\path\\to\\projectdir\\folder1','.'),
('F:\\path\\to\\projectdir\\folder1\\*.kv','.\\folder1'),
('F:\\path\\to\\projectdir\\folder1\\img','\\folder1'),
('F:\\path\\to\\projectdir\\folder1\\img\\*png','.\\folder1\\img'),
('F:\\path\\to\\projectdir\\form','.'),
('F:\\path\\to\\projectdir\\form\\*.kv','.\\form'),
('F:\\path\\to\\projectdir\\management','.'),
('F:\\path\\to\\projectdir\\management\\*.kv','.\\management')
],
             hiddenimports=[],
             hookspath=[kivymd_hooks_path],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False
             )
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
          [],
          name='YourEXEname',
          icon='F:\\path\\to\\projectdir\\FILE.ico',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True
          )

 

Build command :

PyInstaller --clean --onefile yourspecfile.spec

In here you have console and debug enabled , change that to "False" if you don't need it.

Tip: If your are not able to see the console log and its closing before you can see , Open a terminal in the location of exe and use "./main.exe" to see the logs after it crashs