繁体   English   中英

Kivy 使用 PyInstaller 执行。 [Failed to execute script main] 因为 SoundLoader

[英]Kivy to Exe with PyInstaller. [Failed to execute script main] because of SoundLoader

我正在尝试将 my.py 文件转换为 .exe。 我在 my.py 文件中使用 kivy。我意识到检测到致命错误。如果我使用SoundLoader.load('test.wav')则无法执行脚本主要错误。 主要文件:

from kivy.app import App
from kivy.core.audio import SoundLoader
from kivy.uix.screenmanager import ScreenManager
class Manager(ScreenManager):
    sound = SoundLoader.load('test.wav')
    sound.play()
class testapp(App):
    def build(self):
        return Manager()
if __name__ == '__main__':
    testapp().run()

如果我运行 my.py 文件,我会在 windows 和 linux 系统上听到声音。我按照以下步骤创建我的 exe: KIVY package 为 Windows 如果我不使用 SoundLoader 行,我的 exe 就会运行。 但是,如果我添加它,我什至无法打开控制台或应用程序,因为会出现此错误。感谢您的建议。

如果您有同样的问题,请在.spec文件中修复此行:

from kivy_deps import sdl2, glew, gstreamer
...
...
datas=[('Files\test.wav','.')
...
...
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins +  gstreamer.dep_bins)],
...
...

为我工作..

这对我有用。

from kivy_deps import sdl2, glew, gstreamer

datas=[(r'Assets', 'bullet.wav'),
         (r'Assets', 'music.wav'),
         (r'Assets', 'Explosion.wav')],

*[Tree(p) for p in
           (sdl2.dep_bins +
           glew.dep_bins +  gstreamer.dep_bins)],

接下来的事情帮助了我:

python -m pip install kivy[full]

这与之前的 conda 安装重叠:

conda install -c conda-forge kivy

之后 mp3 文件播放正常。

从 pip(我的目录)安装后的软件包更改:

f:\pzz\lib\site-packages (from kivy[full]) (0.3.1)kivy-deps.glew~=0.3.1 (来自 kivy[full])(0.3.1)

f:\pzz\lib\site-packages (from kivy[full]) (0.3.3)kivy-deps.gstreamer~=0.3.3 (来自 kivy[full])(0.3.3)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM