2

I'm trying to write a sample Python application using Pygame:

import pygame, sys
from pygame.locals import *

pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello world!')
while True: # main game loop    
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()

However, PyDev complains that init() is an undefined variable even though it recognizes the Pygame library. I'm using Python 2.7.6 as the interpretor.

Here's the stack trace:

Traceback (most recent call last):
  File "/Users/dannychia/Documents/workspace/PygameSample/PygameSample.py", line 6, in <module>
    import pygame, sys
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
    from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper

Anyone have a solution?

Danny
  • 705
  • 1
  • 7
  • 23
  • 1
    The exception indicates that the Pygame shared library is for the wrong architecture. Are you sure you installed the correct Pygame package for your system? – Blckknght May 05 '14 at 00:15
  • I'm using Mac OS X 10.9.2 on a MacBook Pro with a Core 2 Duo P8700 processor. The installer I used is the first one listed under "Macintosh" on the Pygame downloads site: http://www.pygame.org/download.shtml (pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg) – Danny May 05 '14 at 00:28
  • Maybe try other versions. – furas May 05 '14 at 01:47

1 Answers1

2

Here are some suggestions. One of these should solve the problem:

-I see that your release is the 32 bit version. Considering you probably have a 64 bit computer, it is possible that you have a 64 bit python distribution. This error is sometimes caused by bit rate differences. You can check the bit rate of the python distribution like so:

import platform
platform.architecture()

-According to this question, uninstalling pygame, and redownloading and installing it seems to fix the problem sometimes.

Community
  • 1
  • 1
trevorKirkby
  • 1,886
  • 20
  • 47
  • Yeah, it turned out it was an architecture issue. I installed Pygame on a 32-bit Windows machine using a similar setup, and there were no problems. Thanks for the answer! – Danny May 07 '14 at 03:31