You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows平台Kivy应用启动后自动关闭问题求助

Windows下Kivy打包应用启动秒退+递归深度溢出问题求助

问题详情

  • 自制Kivy应用在Windows系统启动后,弹窗仅显示半秒就自动关闭,弹窗截图:启动弹窗截图
  • 尝试另一种打包方式时,出现错误:执行脚本'main'失败,未处理异常:超出最大递归深度
  • 已确认Kivy已正确安装,所有操作均在虚拟环境中完成

可正常运行的原代码

import os, sys
from kivy.resources import resource_add_path, resource_find
import kivy
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.app import App
kivy.require("2.1.0")

class Test(App):
    def build(self):

        def Button_Click(instance):
            lbl.text = "You clicked the button !"

        bx = BoxLayout(orientation = "vertical")
        btn = Button(text = "Click Me !")
        btn.bind(on_press = Button_Click)
        lbl = Label(color = "red")
        bx.add_widget(btn)
        bx.add_widget(lbl)

        return bx

if __name__ == '__main__':
    if hasattr(sys, '_MEIPASS'):
        resource_add_path(os.path.join(sys._MEIPASS))
    Test().run()

使用的.spec文件

from kivy_deps import sdl2, glew

# -*- mode: python ; coding: utf-8 -*- 


block_cipher = None


a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    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='main',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=False,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe, Tree('C:\\Users\\loddo\\PycharmProjects\\TEST\\'),
    a.binaries,
    a.zipfiles,
    a.datas,
    *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
    strip=False,
    upx=True,
    upx_exclude=[],
    name='main',
)

已安装包列表

已安装包截图

内容的提问来源于stack exchange,提问作者Tarezze

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 11:31:13