无法运行Pygame脚本来播放通过cx_Freez编译的OGG文件

2024-03-28 10:10:28 发布

您现在位置:Python中文网/ 问答频道 /正文

当我编译以下脚本时:

# play.py

import os, re
import pygame.mixer

pygame.mixer.init(11025)
pygame.mixer.music.load('song.ogg')
pygame.mixer.music.play(-1)

os.system("PAUSE")

使用以下设置.py

^{pr2}$

通过:

python setup.py build

执行em>播放.exe给出了以下错误:

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
    exec(code, m.__dict__)
  File "play.py", line 7, in <module>
pygame.error: Couldn't open 'song.ogg'

脚本在编译前运行良好,是的,我确实把歌曲.oggexe的目录中。顺便说一下歌曲.ogg我已经检查过了。有什么想法吗?在

如果我把它改成歌曲.wav它工作得很好,但是WAV文件太大了,我无法使用。而且MP3不能正常工作。在


Tags: inpyimport脚本playsongosline
3条回答

扩展您的答案,我找到了这个针对mac用户的解决方案(假设您使用Homebrew来安装pygame):

    brew install libogg
    brew install libvorbis
    brew install sdl_mixer  with-libvorbis

如果在运行第3个命令后收到一条消息“警告:sol効mixer-1.2.12 already installed.”(警告:sol劬u mixer-1.2.12 already installed.),则将其替换为以下命令:

^{pr2}$

供参考:can't open sound files using pygame on a mac

通过Process Explorer我发现我需要复制libogg.dlllibvorbis.dlllibvorbisfile.dll从Python33\Lib\site packages\pygame到我的冻结程序目录。在

计算机无法打开歌曲.ogg因为cx_freeze没有在编译中包含歌曲。您应该尝试将歌曲文件包含到setup.py脚本中。使用类似下面的setup.py脚本。在

from cx_Freeze import setup, Executable

exe=Executable(
     script="play.py",
     base="Win32Gui",
     )
includefiles=[song.ogg]
includes=[]
excludes=[]
packages=[]
setup(

     version = "0.0",
     description = "Description",
     author = "Name",
     name = "Play",
     options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
     executables = [exe]
     )

相关问题 更多 >