所以,我试图用python代码制作一个.exe,.exe已经完成了,但是它没有打开。没有留言什么都没有。我正在检查日志,但那里没有问题,所以我完全处于黑暗之中。我正在使用以下.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)如果你们有什么可以帮助我的东西,请告诉我。
发布于 2020-07-03 01:27:24
好吧,所以我想通了。首先,如果您有此问题,您必须首先在代码中添加以下一行:
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()这将防止应用程序不打开(就像它看起来像它的加载,但没有打开)。在此之后,您需要使用这样的规范进行构建:
# -*- 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')现在,这里有些事情是非常重要的,如果没有它,应用程序可能无法运行,它们是:
为我解决了这个问题。
发布于 2020-06-21 15:05:01
要将.py文件转换为.exe,可以使用冰冻模块。要安装它,打开cmd并在安装后输入pip install cx_freeze,创建一个新的.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> ")]
)将此文件保存为setup.py或任何要保存它的名称,并将该文件保存在同一个文件夹中。然后,在该文件夹中,打开“打开命令窗口”,您可以同时按shift键和右键单击。然后在命令类型python setup.py(or the name you have given to new file) build中。它将创建一个构建文件夹,在该文件夹中,您将找到您的.exe文件。
发布于 2021-08-16 19:50:45
如果它与我的问题相同,引用我们的旧openGL,1.1在我的情况下,我不能升级,因为我的图形卡也是旧的。所以你不能把这行放在你的主代码上:
from kivy_deps import angle
import os
os.environ['KIVY_GL_BACKEND'] ='angle_sdl2'之后,您需要导入.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')若要创建exe,请执行。确保您拥有UPX,如果没有,请下载并将其放在运行pyinstaller的同一个目录中。
https://stackoverflow.com/questions/62500014
复制相似问题