Python - 执行exe文件时出现pygame错误 [英] Python - pygame error when executing exe file

查看:69
本文介绍了Python - 执行exe文件时出现pygame错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在为自己做一个小项目,使用 pygame 和 tkinter 来构建一个 mp3 播放器.使用visual studio运行程序时一切正常,但是当我使用pyinstaller将程序转换为.exe文件并尝试运行时,出现以下内容:
pygame.mixer.load(song)
pygame.error
执行脚本失败

So, I'm working on a little project for myself, using pygame and tkinter to build an mp3 player. Everything works when running the program using visual studio, but when I turned the program to an .exe file using pyinstaller and tried to run in, the following appeared:
pygame.mixer.load(song)
pygame.error
Failed to execute script

我已经尝试了所有方法,但它总是告诉我同样的情况.在这里你可以看到我如何称呼这首歌:

I've tried everything, but it keeps telling me the same. Here you can see how I call the song:

pygame.init()
pygame.mixer.init()

song = path + '\music\\' + selected_song
pygame.mixer.music.load(song)

作为 path + '\music\\' ,歌曲所在的目录.和slected_song歌曲名称+'.mp3'.

Being path + '\music\\' , the directory where the songs are. And slected_song the name of the song + '.mp3'.

推荐答案

你需要双反斜杠:

来自:

song = path + '\music\\' + selected_song

致:

song = path + '\\music\\' + selected_song

或者:

song = f"{path}\\{music}\\{selected_song}"

这篇关于Python - 执行exe文件时出现pygame错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆