[英]Can't create a .exe with python kivy on windows (Pyinstaller)
So, I'm trying to make a.exe from a python kivy code, The.exe is made, but it doesn't open.所以,我试图从 python kivy 代码制作一个.exe,制作了.exe,但它没有打开。 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
我正在使用以下.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.如果你们有任何可以帮助我的东西(任何东西),请告诉我。
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.这为我解决了问题。
To convert your.py file to.exe you can use cx_freeze module.要将 .py 文件转换为 .exe,您可以使用cx_freeze模块。 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.要安装它,请打开您的 cmd 并键入
pip install cx_freeze
安装后创建一个 new.py 文件并添加以下代码。
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.将此文件另存为 setup.py 或您要保存的任何名称,并将此文件保存在同一文件夹中。 Then in that folder open the "open command window here" you can do this by pressing the shift key and right-click simultaneously.
然后在该文件夹中打开“在此处打开命令 window”,您可以通过同时按住 Shift 键和右键单击来执行此操作。 Then in the command type
python setup.py(or the name you have given to new file) build
.然后在命令中键入
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.它将创建一个构建文件夹,在该文件夹中,您将找到您的 .exe 文件。
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.如果是和我一样的问题,指的是我们老的openGL,我的是1.1,我的显卡也老了,升级不了。 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:在此之后,您需要在 .spec 文件中导入:
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.创建exe。 make sure you have the UPX, if you don't, download and put it in the same directory you are runing the pyinstaller.
确保你有 UPX,如果没有,请下载并将其放在运行 pyinstaller 的同一目录中。
So, I'm trying to make a.exe from a python kivy code, The.exe is made, but it doesn't open.所以,我正在尝试从 python kivy 代码制作 a.exe,制作了 The.exe,但它没有打开。 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
我正在使用以下.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.如果你们有什么可以帮助我的(任何事情),请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.