簡體   English   中英

Pygame: pygame.error: 無法打開文件 .ogg

[英]Pygame: pygame.error: Unable to open file .ogg

OS X 版本。 10.11.6 ;

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

Pygame 版本。 homebrew/python/pygame: stable 1.9.2a0, HEADpip3Homebrew都會遇到同樣的錯誤,我將在下面說明);

Xcode 版本。 Xcode 8.2 Build version 8C38

終端上我運行:

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() ,但仍然是同樣的錯誤,所以我想知道上面的兩個錯誤是否相關?

Reddit 上的帖子中,我發現該解決方案非常適合播放 .ogg 音樂文件。

如果您使用的是 Homebrew,請在終端上輸入以下內容:(在我運行以下代碼之前,我會通過brew list檢查我是否安裝了以下任何一個)

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

如果您安裝了 sol_mixer,但您的程序仍然無法運行(是的,它也不適用於我),

嘗試:

brew reinstall sdl_mixer --with-libvorbis

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM