I am learning python using this website
I am trying to load an image like so:
background_image = pygame.image.load("background.jpg").convert()
I have found several other posts asking the same question, and all the answers are telling the poster to make sure the image is in the same folder as the .py
file. Well, it is. I double checked.
I also tried putting it into a subfolder called 'images'
and using this.
background_image = pygame.image.load(os.path.join("images","background.jpg")).convert()
In both cases I get the following error message.
pygame.error: Couldn't open saturn_family1.jpg
or
pygame.error: Couldn't open images\saturn_family1.jpg
When using the absolute path, it works. But shouldn't I be able to use a relative path like this?
Also, this happens when using the script
package to execute in Atom. But when executing the actual python file, it works.
I am very frustrated, this doesn't seem to make any sense! What's going on?
The full error message is:
C:\Users\Manu\Dropbox\Python\ProgramArcadeGames
Traceback (most recent call last):
File "C:\Users\Manu\Dropbox\Python\ProgramArcadeGames\Ch11\11_graphicsAndSound.py", line 26, in <module>
background_image = pygame.image.load(os.path.join("images","saturn_family1.jpg")).convert()
pygame.error: Couldn't open images\saturn_family1.jpg
[Finished in 0.815s]
UPDATE: I ran the exact same code in sublime and it worked fine. I am assuming this is a problem with Atom, so I will just use Sublime from now on. Thanks to everyone who tried to help!