Reputation: 3
I'm writing a game in python using pygame. I have a code:
imageJBird = pygame.image.load("jbirdnapis.png")
Everything was working but suddenly it stopped. Now I have an error "Couldn't open jbirdnapis.png". The image is in the same directory as the code. I use Pycharm to execute the game. It works on other contributor's computer - also Ubuntu, the same version. We have the same version from git repository. Any ideas?
Upvotes: 0
Views: 861
Reputation: 142641
It runs script in folder view
, not in view/states
so it is searching image in view
.
You can get script's folder and add to all images.
import os
folder = os.path.dirname(os.path.realpath(__file__))
imageJBird = pygame.image.load(os.paht.join(folder, "jbirdnapis.png"))
It will be usefull when you will run in different places.
Upvotes: 0