程序在启动可执行文件时出错而停止



我有一个正在运行的kivy应用程序,当我从vscode启动它时,它运行良好。但是当我尝试用制作一个exe文件时

pyinstaller --onefile --icon=icons/levermannApp.ico --exclude-module matplotlib LevermannApp.py

然后启动程序我得到这个错误消息

[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 "kivycore__init__.py", line 70, in core_select_lib
File "kivycorewindowwindow_sdl2.py", line 152, in __init__
File "kivycorewindow__init__.py", line 982, in __init__
File "kivycorewindowwindow_sdl2.py", line 311, in create_window
File "kivycorewindow__init__.py", line 1268, in create_window
File "kivygraphicsinstructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
File "kivycoreimage__init__.py", line 561, in __init__
File "kivycoreimage__init__.py", line 754, in _set_filename
File "kivycoreimage__init__.py", line 460, in load
File "kivycoreimage__init__.py", line 223, in __init__
File "kivycoreimageimg_sdl2.py", line 47, in load
Traceback (most recent call last):
File "LevermannApp.py", line 28, in <module>
class MyLayout(Widget):
File "LevermannApp.py", line 29, in MyLayout
Window.size = (550, 700)
AttributeError: 'NoneType' object has no attribute 'size'
[49080] Failed to execute script LevermannApp

我的部分代码如下:

class MyLayout(Widget):
Window.size = (550, 700)
class LevermannScore(App):
def build(self):
return MyLayout()
if __name__ == "__main__":
LevermannScore().run()

我的规范文件如下:

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

block_cipher = None

a = Analysis(['LevermannApp.py'],
pathex=['C:\Users\Polzi\Documents\DEV\Python-Private'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=['matplotlib'],
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,
[],
name='LevermannApp',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True , icon='icons\levermannApp.ico')

你知道为什么这个程序在vscode下运行得很好,但不能执行吗?(过去我已经可以用pyinstaller为这个程序制作一个exe文件,但现在我再试一次,得到了上面的错误…(

我想我终于能够通过定义规范文件来解决这个问题,如下所示:

# -*- mode: python -*- 

import os
from kivy_deps import sdl2, glew

spec_root = os.path.abspath(SPECPATH)
block_cipher = None
app_name = 'LevermannApp'
win_icon = 'icons/levermannApp.ico'

a = Analysis(['LevermannApp.py'],
pathex=['C:\Users\Polzi\Documents\DEV\Python-Private'],
binaries=None,
datas=[('*.kv', '.')],
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,
icon=win_icon)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=False,
name=app_name)

然后用命令简单地开始编译

pyinstaller LevermannApp.spec

顺便说一句,它并没有被编译成一个单独的exe文件(我在使用pyinstaller时通常有这个文件(,但这对我来说不是什么大问题,exe文件运行良好。(我将把它和Inno Setup一起使用,最后把它编译成Setup.exe(

相关内容

最新更新