Somebody asked a similar question here, but it didn't get answered.
I have Python 2.7.11, OSX 10.11, and pygame 1.9.1. Every time I run the program, the window appears, and then closes with the error "Segmentation fault: 11". I got this from the pygame tutorials, and then modified it slightly to prevent an infinite loop. (the same error occurs even if I use the "while 1" loop used in the tutorial.)
Why is this happening and how can I fix it? Thanks!
import sys, pygame
pygame.init()
size = width,height = 320,240
speed = [2,2]
black = 0,0,0
screen = pygame.display.set_mode(size)
ball = pygame.image.load("ball.gif")
ballrect = ball.get_rect()
for i in range(100):
ballrect = ballrect.move(speed)
if ballrect.left < 1 or ballrect.right > width - 1:
speed[0] = -speed[0]
if ballrect.top < 1 or ballrect.bottom > height - 1:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball,ballrect)
pygame.display.flip()
Just in case anyone else has the same problem, I figured it out. It crashes because the SDL1 that comes with OS X 10.11 is a bit broken.
The solution is to download the runtime library SDL1 from here. Open the dmg after downloading it, and move the SDL.framework file from it into /Library/Frameworks. Since there was already one there, I merged the two, but replace should also work. Pygame works now!
After a bit of research it appears to be a know issue when the interpreter is running in interactive mode. I have found an official python patch that may help. To use it, open a terminal session in Terminal.app (or other shell), then enter:
then
Enter password if prompted! Let me know if this worked!