4

I've been coding for a long time but am working my way through a beginner Python book to get acclimated to the syntax. I've worked through some serious obstacles getting pygame installed and have encountered an insurmountable problem. This simple program will display a window, but the background image will not show up:

#game.py
from livewires import games

games.init(screen_width = 640, screen_height = 480, fps = 50)

wall_image = games.load_image("wall.jpg", transparent = False)
games.screen.background = wall_image

games.screen.mainloop()

I've checked triple-checked that the wall.jpg file exists and is valid. It is and lives in the same folder as the python file game.py.

There are no errors. The pygame import seems to work find and reports the following message to stdout:

pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html

I'm running this with python 2.7.15, which is AFAIK the default/native python that runs on OSX Mojave. I tried running it with python 3.7, but livewires is apparently not compatible with that version of python.

Can anyone tell me how to fix this? I'd love to just get it working so I can grind thru the rest of this book.

NOTE: the book says it uses a modified version of livewires (which also looks fairly old now that I look at it). I'm not sure what the ettiquette is for sharing files here, so I won't try to post a zip or anything. You should be able to create a livewires sub-folder in the same folder where you've store game.py and put these four files in it:

__init__.py

beginners.py

color.py

games.py

EDIT: This code works fine on my Ubuntu desktop when I set the code up with PyCharm. This environment has python 2.7.6, pygame 1.9.4, the livewires code I've specified here.

The problem appears to be specific to pygame running on OSX mojave, but in the comments @Lau-Real says it works on his OSX-Mojave machine.

S. Imp
  • 2,425
  • 8
  • 18
  • can u run the code u uploaded? I tried to debug ur code and got an error: `AttributeError: 'module' object has no attribute 'init'` – Lau Real Jan 22 '19 at 07:04
  • @LauReal yes! As I describe in the OP, the code runs without a single error, outputs the pygame message to stdout, and shows a window, but the window does not show the background image I've specified. I edited the post to include links to the livewire source, which may make a difference? – S. Imp Jan 22 '19 at 07:25
  • Yes, now I can run ur code, and, it's working. – Lau Real Jan 22 '19 at 07:40
  • So you see a window and the jpeg image is properly loaded? What OS are you running? What version of python? What version of pygame? – S. Imp Jan 22 '19 at 07:42
  • OS: OSX Mojave 10.14.2 with python2.7.15, pygame1.9.4. Sorry but stackoverflow can NOT upload image to comments. – Lau Real Jan 22 '19 at 07:47
  • holy cow! This suggests to me that something is wrong with my pygame installation. How did you install pygame? Do you have a recipe? Or can you suggest what might be causing this problem for me? I'm not getting any errors. – S. Imp Jan 22 '19 at 07:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/187106/discussion-between-lau-real-and-s-imp). – Lau Real Jan 22 '19 at 07:54
  • @LauReal I have used PyCharm on my Ubuntu desktop and my code works. I have also tried using PyCharm on my macBook but it doesn't work. I'm wondering if it might somehow be related to my attempts to install pygame before. I believe something is broken about pygame on the mac, but don't fully understand the relation between the built-in python and the interpreters managed by PyCharm. – S. Imp Jan 22 '19 at 18:47
  • thats weired. Have you tired remove pygame with homebrew and reinstall it with pycharm? – Lau Real Jan 23 '19 at 01:14
  • @LauReal I did precisely that. Uninstalled mercurial, et. al., and used PyCharm to create a new project, add my livewire files, create the game.py file. This works fine on my Ubuntu machine (the background image shows fine) but it will not work on the Mac. I'm wondering if there might be some vestigial library mucking stuff up. – S. Imp Jan 23 '19 at 01:32
  • Any fix to this guys? I'm using 2.7.14 and 1.9.4 pygame.... ahhh mojave – Marin Feb 12 '19 at 02:20
  • 1
    @Marin unlike Lau-Real, I was not able to get it working on my MacBook at all. It does seem to work just fine on my Ubuntu workstation, so I have been able to proceed with my project on that machine without trouble. – S. Imp Feb 12 '19 at 19:52
  • THank you @S.Imp I guess I'll have to carry on with linux too.... – Marin Feb 12 '19 at 20:59

0 Answers0