Я новичок в программировании, поэтому я поставил перед собой задачу создать Pong, что я и сделал. Теперь я хочу поделиться им с парой друзей, поэтому я решил попробовать использовать pyinstaller (пробовал cx_Freeze). В этой игре Pong у меня есть 3 звуковых эффекта, расположенных в папке "sfx". Итак, я изучил включение файлов с помощью pyinstaller, поэтому в моем файле .spec говорится:
added_files = [
('E:\Game Development Stuff\Python 3\Games\Pong\sfx\hitOutline.ogg', 'sfx'),
('E:\Game Development Stuff\Python 3\Games\Pong\sfx\hitPaddle.ogg', 'sfx'),
('E:\Game Development Stuff\Python 3\Games\Pong\sfx/score.ogg', 'sfx')
]
a = Analysis(['pong.py'],
pathex=['E:\\Game Development Stuff\\Python 3\\Games\\Pong'],
binaries=None,
datas=added_files,
и в самой программе Pong я использую этот код для получения пути:
def resource_path(relative):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, relative)
return os.path.join(relative)
fileDir = os.path.dirname(os.path.realpath('__file__'))
hitPaddle = resource_path(os.path.join(fileDir, "sfx", "hitPaddle.ogg"))
hitOutline = resource_path(os.path.join(fileDir, "sfx", "hitOutline.ogg"))
score = resource_path(os.path.join(fileDir, "sfx", "score.ogg"))
hitPaddleSound=pygame.mixer.Sound(hitPaddle)
hitOutlineSound=pygame.mixer.Sound(hitOutline)
scoreSound=pygame.mixer.Sound(score)
Поэтому я создаю exe-файл с помощью pyinstaller (с помощью команды pyinstaller pong.spec), но когда я открываю файл pong.exe, в командном окне появляется сообщение:
Traceback "<string>", Unable to open file 'E:\\Game Development Stuff\\Python 3\\Games\\Pong\\dist\\pong\\sfx\\hitPaddle.ogg'
но точно по тому же пути находится hitPaddle.ogg. Мне кажется, что pygame не может его найти по какой-то странной причине?