2016-12-18 100 views
1

OS X ver。 10.11.6;Pygame:pygame.error:無法打開文件.ogg

Python3 ver。 stable 3.5.2 (bottled), devel 3.6.0rc1, HEAD(通過Homebrew);

Pygame ver。 homebrew/python/pygame: stable 1.9.2a0, HEADpip3 and Homebrew將得到同樣的錯誤,我會在下面說明);

Xcode ver。 Xcode 8.2Build version 8C38

終端I運行:

python3 BattleCity.py

,其中(BattleCity.py)是遊戲的源代碼,和pygame的模塊在它導入。

以下是終端結果:(爲了便於閱讀,我重新安排壓痕,並添加/刪除一些不可見的字符)

2016-12-18 21:26:12.739 Python[1600:53113] 21:26:12.739 
WARNING:140: 
This application, or a library it uses, is using the deprecated Carbon Component 
Manager for hosting Audio Units. 

Support for this will be removed in a future release. 

Also, this makes the host incompatible with version 3 audio units. 

Please transition to the API's in AudioComponent.h. 

Traceback (most recent call last): 
    File "BattleCity.py", line 2074, in <module> 
    game = Game() 
    File "BattleCity.py", line 1266, in __init__ 
    sounds["start"] = pygame.mixer.Sound("sounds/gamestart.ogg") 
pygame.error: Unable to open file 'sounds/gamestart.ogg' 

我已經經歷了一些相關的問題,但他們的解決方案搜索不工作。

在文件我已經使用pygame.init(),但仍然是相同的錯誤,所以我不知道上面的兩個錯誤是否有關?

回答

0

a post on Reddit我發現該解決方案完全適用於播放.ogg音樂文件。

如果你使用自制,鍵入終端如下: (之前我運行下面的代碼,我檢查我是否安裝了brew list低於任何一個)

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

如果您已經安裝sol_mixer和你的程序仍然不工作(是的,它也沒有爲我),

嘗試:

brew reinstall sdl_mixer --with-libvorbis