Python Forum

Full Version: pip install pygame choking on SDL dependency
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I'm working my way through a book to learn python. Nearly done. Penultimate chapter calls for an install of pygame to develop a simple game. Turns out that installing pygame is a pain.

I'm using a MacBook which has python 2.7 installed. I'd like to avoid changing this lest I break something important.

I installed pip:
sudo python -m ensurepip --default-pip --upgrade
And tried to install pygame:
sudo pip install pygame
This results in the operation proceeding until it hits a fatal error:
src/scrap.c:27:10: fatal error: 'SDL.h' file not found
Having sniffed around a bit, I see that there are some dependencies (SDL) and the solutions I've seen recommend installing these with homebrew. This, of course, necessitates installing homebrew also.

Must I really install homebrew? I use this laptop for some sensitive work and the idea of just installing these tools stacked upon tools is a bit disconcerting.
I dont own a mac, but i see people that do use homebrew a lot. So i cant say exactly what to do without homebrew. It seems mac users have the most issues. Homebrew is just a package manager. Its purpose is to simplify things.

https://python-forum.io/Thread-PyGame-In...leshooting
(Jan-21-2019, 03:50 AM)metulburr Wrote: [ -> ]Homebrew is just a package manager. Its purpose is to simplify things.
I'm aware of this. What concerns me is the blind reliance on it while it alters the permissions in your bin folder to be less secure. I'd much prefer if I could just install with pip alone.

(Jan-21-2019, 03:50 AM)metulburr Wrote: [ -> ]https://python-forum.io/Thread-PyGame-In...leshooting
Thank you so much for this. Really disappointing that OSX has such trouble. I'm usually a linux guy, but my laptop is a mac.

It's also worth noting that a homebrew install of python 3 will cause the command python to use python 3, whereas OSX relies on a default installation of python 2:
https://docs.python-guide.org/starting/install3/osx/

Seems to me like this might cause some weirdness.
Another install option.
Scroll down to Max Os X install section.

pygame require sdl 1.2 +. pygame doesn't currently work with sdl2.

You can also try pygame_sdl2 which can open another can worms.
(Jan-21-2019, 02:46 PM)sneakyimp Wrote: [ -> ]It's also worth noting that a homebrew install of python 3 will cause the command python to use python 3, whereas OSX relies on a default installation of python 2:
Im not sure of what exactly homebrew does or how macs operate. But in linux when you install python3.x via a package manager, it uses python3 to invoke python3.x, and python to invoke python2.x.

(Jan-21-2019, 01:40 AM)sneakyimp Wrote: [ -> ]I'm using a MacBook which has python 2.7 installed.
If your installing pygame for python2.x then why would you need to install python3?

To be honest you might get more help from pygame reddit as there is a larger audience and more chance that others will have macs to help you. If you find a solution please report it back here. I am always looking for pygame install fixes for my troubleshooting tutorial to help mac users out.
https://www.reddit.com/r/pygame/
(Jan-21-2019, 04:52 PM)Windspar Wrote: [ -> ]Another install option.
Scroll down to Max Os X install section.
It's good to know the other end of the spectrum from installing homebrew. I.e., we can manually chase down the dependencies.

(Jan-21-2019, 04:52 PM)Windspar Wrote: [ -> ]You can also try pygame_sdl2 which can open another can worms.
More good info. Thank you!

(Jan-21-2019, 05:16 PM)metulburr Wrote: [ -> ]
(Jan-21-2019, 02:46 PM)sneakyimp Wrote: [ -> ]It's also worth noting that a homebrew install of python 3 will cause the command python to use python 3, whereas OSX relies on a default installation of python 2:
Im not sure of what exactly homebrew does or how macs operate. But in linux when you install python3.x via a package manager, it uses python3 to invoke python3.x, and python to invoke python2.x.
That sounds like linux works as expected -- i.e., whatever the default, system-installed python is will continue to be associated with the python command.

(Jan-21-2019, 05:16 PM)metulburr Wrote: [ -> ]
(Jan-21-2019, 01:40 AM)sneakyimp Wrote: [ -> ]I'm using a MacBook which has python 2.7 installed.
If your installing pygame for python2.x then why would you need to install python3?
All the results I've been able to find for installing pygame appear to include installation of python3. As I mentioned in my OP, pip choked trying to install pygame for python2, which is what launched this quest. I'm leaning toward installation of python3, which is not supposed to interfere with any native OSX functions, but I'm wary.

A better question would be "why does Apple install python2." I can only surmise that it has something to do with legacy code compatibility.

(Jan-21-2019, 05:16 PM)metulburr Wrote: [ -> ]To be honest you might get more help from pygame reddit as there is a larger audience and more chance that others will have macs to help you. If you find a solution please report it back here. I am always looking for pygame install fixes for my troubleshooting tutorial to help mac users out.
https://www.reddit.com/r/pygame/
Thanks for this tip. I may head over there. Although it'd be nice if I could get authoritative answers from this forum, which is recommended by python.org.
I tried installing python 3 and am happy to report that, contrary to what you might read elsewhere, this installation does not change the python command to use python 3. This also allowed me to install pygame easily in a virtualenv with a simple pip install pygame but did not solve my problem because apparently livewires is not compatible with python 3.

So I broke down and installed homebrew and installed a long list of stuff per this link. My approach was to try and make sure I got the major libraries installed then try the pip install again. This may not be a complete list of brew commands but it appears to have resolved any errors:
Output:
# install home-brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap caskroom/cask brew install caskroom/cask/brew-cask brew cask install xquartz brew linkapps python brew install sdl sdl_image sdl_ttf portmidi libogg libvorbis brew install sdl_mixer --with-libvorbis brew tap homebrew/headonly brew install smpeg brew install mercurial
I then ran pip install pygame and it appears to have run to completion. I was able to run python -m pygame.tests and it skips a few but otherwise reports OK:
Output:
Ran 715 tests in 19.033s OK
My short program now runs without any errors at all and the stdout reports pygame:
Output:
pygame 1.9.4 Hello from the pygame community. https://www.pygame.org/contribute.html
However, it just shows a window without the background image. I’ve checked, double-checked, triple-checked that the image exists, is valid, and the path is correct. I’ve tried an absolute path. It just won’t show the jpeg.

My game script is so far very short. Just this:
from livewires import games

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

wall_image = games.load_image("/Users/yamo/trash/python/ch11/wall.jpg", transparent = False)
games.screen.background = wall_image

games.screen.mainloop()
If anyone can help me get this working, I’d be most grateful.
this is a whole separate issue than installing pygame. I would make a new thread with your latest problem. It would of been nice to know that you were initially trying to get livewires to install (a pygame wrapper). Not pygame to use directly to run games. Trying to research what livewires actually is, i came across this...which may or may not be useful. Unfortunately i have never heard of livewires so i cannot also help you with that.
hi mate- not sure about your problem but hope you sovle it soon! Pygame can be a bitch to start with but trust me you will get there!! Smile Wink Big Grin
(Jan-22-2019, 12:49 PM)DouglasStewart41 Wrote: [ -> ]hi mate- not sure about your problem but hope you sovle it soon! Pygame can be a bitch to start with but trust me you will get there!! Smile Wink Big Grin
I appreciate the encouragement. I've no idea where the problem is. The window appears, but no background image. There is no error message anywhere to clue me in. Very frustrating.
Pages: 1 2 3