要保持简短而甜美。我正在尝试使用pygame的混音器播放一首歌。我在字典中有歌曲标题,并且正在使用它访问存储文件的名称。当我选择播放歌曲时,出现此错误。
Traceback (most recent call last):
File "c:\Users\me\Documents\Bella\Music.py", line 50, in <module>
song_look_up_by_artist("artist1", thisdict)
File "c:\Users\me\Documents\Bella\Music.py",line 37, in song_look_up_by_artist
mixer.music.load(toplay)
pygame.error: Failed loading libmpg123-0.dll: The specified module could not be found.
我发现了一些解决该问题的帖子。他们都说关闭您的IDE并重新启动计算机。我已经尝试过了,什么也没有。我还找到了可能找不到的文件,但pygame的文件夹中有libmpg123-0.dll。 python文件和.mp3文件都在同一文件夹中。我也把libmpg123-0.dll也放在那里。我也使用python 3.8.6,Windows 10,VScode作为我的IDE。我不知道真正的问题是什么。如果有帮助的话,这是我的代码。
我在:\ Users \ me \ AppData \ Local \ Packages \ PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0 \ LocalCache \ local-packages \ Python38 \ site-packages中找到了libmpg123-0.dll文件
from pygame import mixer
import pygame
thisdict = {
("artist1", "song1"): 'KDA.mp3',
("artist3", "song1"): 'Nanners.mp3',
("artist1", "song2"): 'ATL.mp3',
}
mixer.init()
#mixer.music.load("C:\Users\Connor Ferwerda\Downloads\\")
#mixer.music.play()
def song_look_up_by_artist(artist, thisdict):
#get list of songs that match artist
mixer.init()
song_list = []
for x in thisdict:
if x[0] == artist:
song_list.append(x[1])
#lets user pick if they wanna play a song
answer = input("Would you like to play a song by " + artist + "? " )
print("\n")
if answer == "quit":
print("ok")
elif answer == "yes":
print("Here is there list of songs: ")
print(song_list)
#they pick which song
answer = input("Which song? ")
for song in song_list:
if answer == song:
toplay = thisdict[(artist, answer)]
mixer.music.load(toplay)
mixer.music.play()
while mixer.music.get_busy():
print("playing...")
pygame.time.Clock().tick(10)
elif song == song_list[-1]:
print("that doensn't match")
break
song_look_up_by_artist("artist1", thisdict)
谢谢!
答案 0 :(得分:0)
尝试卸载pygame
:
pip uninstall pygame
,然后重新安装它的最新版本:
pip install pygame
答案 1 :(得分:0)
解释器的路径文件错误。对此进行了修复。