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?

3
  • 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? Commented May 5, 2014 at 0: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: pygame.org/download.shtml (pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg) Commented May 5, 2014 at 0:28
  • Maybe try other versions. Commented May 5, 2014 at 1:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.