Skip to main content
 首页 » 编程设计

python之段错误 : 11 when I run Pygame

2024年10月24日11birdshome

有人问过类似的问题here , 但没有得到答复。

我有 Python 2.7.11、OSX 10.11 和 pygame 1.9.1。每次我运行该程序时,该窗口都会出现,然后关闭并显示错误“Segmentation fault: 11”。我从 pygame 教程中得到这个,然后稍微修改它以防止无限循环。 (即使我使用教程中使用的“while 1”循环也会出现同样的错误。)

为什么会发生这种情况,我该如何解决?谢谢!

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() 

请您参考如下方法:

经过一些研究,当解释器以交互模式运行时,这似乎是一个已知问题。我找到了一个可能有帮助的官方 python 补丁。要使用它,请在 Terminal.app(或其他 shell)中打开一个终端 session ,然后输入:

curl -O http://bugs.python.org/file32324/patch_readline_issue_18458.sh 
openssl sha1 patch_readline_issue_18458.sh 
# the digest should be 7cb0ff57820a027dd4ca242eb2418930f8f46b4c 

然后

sh ./patch_readline_issue_18458.sh 

如果出现提示,请输入密码! 让我知道这是否有效!