Reputation: 363
So, I'm trying to make a .exe from a python kivy code, The .exe is made, but it doesn't open. No message, nothing. I'm checking the logs but theres no problem in there, so I'm completely in the dark here. I'm using the following .spec
# -*- mode: python -*-
block_cipher = None
from kivy_deps import sdl2, glew, gstreamer
spec_root = os.path.abspath(SPECPATH)
app_name = 'Gameficacao'
a = Analysis(['C:/Users/Artur/PycharmProjects/gameficacao/Gameficacao.py'],
pathex=[spec_root],
datas=[('C:/Users/Artur/PycharmProjects/gameficacao/*.kv', '.'), ('C:/Users/Artur/PycharmProjects/gameficacao/img/*.png', './img'),('C:/Users/Artur/PycharmProjects/gameficacao/font/*.ttf', './font'),('C:/Users/Artur/PycharmProjects/gameficacao/som/*.mp3', './som')],
hiddenimports=['win32timezone'],
hookspath=[],
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,
[],
exclude_binaries=True,
name=app_name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=False)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p)
for p in (sdl2.dep_bins + glew.dep_bins + gstreamer.dep_bins)],
strip=False,
upx=False,
name=app_name)
If you guys have anything that can help me (ANYTHING), please let me know.
Upvotes: 1
Views: 1731
Reputation: 29
if it is the same problem as my, refers to ours old openGL, 1.1 in my case, and I can't upgrade cause my graphic card is also old. So you cant put this line on your main code:
from kivy_deps import angle
import os
os.environ['KIVY_GL_BACKEND'] ='angle_sdl2'
After this, you need to import in the .spec file:
from kivy_deps import angle,sdl2, glew
coll = COLLECT(exe, Tree('folder of your .kv
file'),
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in(angle.dep_bins +
sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=True,
upx_exclude=[],
name='name')
To create the exe. make sure you have the UPX, if you don't, download and put it in the same directory you are runing the pyinstaller.
Upvotes: 1
Reputation: 363
Ok so I figured it out. FIRST OF ALL, if you are having this problem, you will have to first add the following line to your code:
def reset():
import kivy.core.window as window
from kivy.base import EventLoop
if not EventLoop.event_listeners:
from kivy.cache import Cache
window.Window = window.core_select_lib('window', window.window_impl, True)
Cache.print_usage()
for cat in Cache._categories:
Cache._objects[cat] = {}
if __name__ == '__main__':
reset()
'your app name here'().run()
That will prevent the app from not opening (like when it looks like its loading but nothing opens). AFTER THAT, you wanna build using the spec like this:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
from kivy_deps import sdl2, glew, gstreamer
a = Analysis(['C:\\Users\\Artur\\PycharmProjects\\gameficacao\\Gameficacao.py'],
pathex=['C:\\Users\\Artur\\Desktop\\Trabalho\\Gameficacao'],
binaries=[],
datas=[('C:/Users/Artur/PycharmProjects/gameficacao/*.kv', '.'), ('C:/Users/Artur/PycharmProjects/gameficacao/img/*.png', './img'),('C:/Users/Artur/PycharmProjects/gameficacao/font/*.ttf', './font'),('C:/Users/Artur/PycharmProjects/gameficacao/som/*.mp3', './som')],
hiddenimports=['pkg_resources.py2_warn','win32timezone','six','packaging','packaging.version','webbrowser','kivy','enchant'],
hookspath=[],
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,
[],
exclude_binaries=True,
name='Gameficacao',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins + gstreamer.dep_bins)],
strip=False,
upx=True,
upx_exclude=[],
name='Gameficacao')
Now, some things are VERY IMPORTANT here and the app probably won't run without it, and those are:
That solved the problem for me.
Upvotes: 3
Reputation: 13
To convert your .py file to .exe you can use cx_freeze module. To install it open your cmd and type pip install cx_freeze
once it is installed make a new .py file and add the below code.
from cx_Freeze import setup, Executable
setup(name = "<anyname>",
version = "<any version>",
description = "<add description you want>",
executables = [Executable(r"<give the path where your python file is
located> ")]
)
save this file as setup.py or any name you want to save it and keep this file in the same folder.
Then in that folder open the "open command window here" you can do this by pressing the shift key and right-click simultaneously.
Then in the command type python setup.py(or the name you have given to new file) build
.
It will create a build folder and in that folder, you will find your .exe file.
Upvotes: 1