M
M
Maxim Siomin2020-06-17 20:11:33
Python
Maxim Siomin, 2020-06-17 20:11:33

Why such an error?

Music should be loaded into the python game, I wrote the following code:

import pygame as pg
pg.init()

bulletSound = pg.mixer.Sound('Sounds/Weapons/Pistols/P92/P92 BULLET.wav')

I run the program and this is the error:
Traceback (most recent call last):
  File "C:\Users\Семья\Desktop\game\main.py", line 45, in <module>
    bulletSound = pg.mixer.Sound('Sounds/Weapons/Pistols/P92/P92 BULLET.wav')
pygame.error: Unable to open file 'Sounds/Weapons/Pistols/P92/P92 BULLET.wav'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-17
@SoreMix

Specify the full path to the file

D
Dmitry, 2020-06-18
@LazyTalent

Try like this:

from pathlib import Path

file_path = Path(__file__).parent.joinpath(r'Sounds/Weapons/Pistols/P92/P92 BULLET.wav')

bulletSound = pg.mixer.Sound(file_path)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question