3

Edit3: Additional information: I was able to get the Eclipse/pygame combo running on Windows... just not on MacOSX.


Edit2: Compiling from the shell also works. Just Eclipse now :) What I've tried in Eclipse:

For the interpreter I use auto-config and it suggests /usr/bin/python as interpreter. Then for PYTHONPATH he suggests all the default stuff and I then add /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages in addition to the rest. I still have the unresolved package "syntax" error in the code, but when compiling the only error he complains about is that there is no appropriate 64-bit architecture.

../Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)


Edit: I've now managed to be able to import pygame within IDLE and initialise pygame. In Eclipse I added the pygame path to PYTHONPATH but Eclipse complains about the architecture.


I want to use pygame in combination with Eclipse, Pydev and Python 2.7.

First I downloaded Python 2.7.3 and installed it. To be able to work in an IDE I installed Pydev on Eclipse. That all works and I am able to work in Eclipse with Pydev and the programs I test run without problems.

Then I went on and downloaded pygame and installed that too. (pygame download)

Now when I try:

import pygame
pygame.init()

Eclipse tells me: unresolved import: pygame and when I try to compile anyway I get following message:

Traceback (most recent call last):
File "/Users/name/Documents/workspace/test_unit/main.py", line 6, in <module>
import pygame
ImportError: No module named pygame

Also when I start the IDLE app and try there to import pygame I get following error:

Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pygame
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

However if I use open Module... via IDLE and then open pygame the module is found. What am I missing?

Philipp
  • 2,376
  • 5
  • 29
  • 47
  • execute python directly from the command prompt/bash shell...etc and try to import pygame. What happens? – Mike McMahon Apr 24 '12 at 20:29
  • `Traceback (most recent call last): File "main.py", line 6, in import pygame File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in 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` – Philipp Apr 24 '12 at 20:42
  • This is what I get for `python main.py` where in main.py is only the following `import pygame` and then `pygame.init()` – Philipp Apr 24 '12 at 20:43

3 Answers3

4

OK, I found the solution how to get it working. The key issues was that Eclipse chooses the 'wrong' interpreter. The Eclipse choice works fine for normal python stuff but when trying to compile pygame things it gets complicated and I get architecture errors.

So what I did:

  1. Get Eclipse Classic 3.7.2 32-bit here and install it.
  2. Install pydev for Eclipse (instructions for that here)
  3. Getting Python 2.7.3 for Mac OS X 10.3 (here) and install it
  4. Getting Pygame 1.9.1 32-bit for Python 2.7 (here) and install it

Now to the proper interpreter. Go to Eclipse->Settings->PyDev->Interpreter - Python and there create a New... interpreter. The one that worked for me is found in /Library/Frameworks/Python.framework/Versions/2.7/bin. There just select the python alias which will link to the correct one then.

Now make sure that your pygame is in your PYTHONPATH. To do so just add a New Folder in the lower half of the current menu and navigate to your pygame path (by default it is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages)

Philipp
  • 2,376
  • 5
  • 29
  • 47
0

Installing Pygame for Mac OS X 10.6.8

Give that a read, it looks like you may be trying to mix and match 32/64bit libraries. This may require you either install the correct version of python to match your dev environment or pygame to match your dev environment.

I ran into this problem before on a 64bit system that required 32bit libraries. The fix was to force python to run in 32bit mode.

The fix to force it into 32 bit mode is include on that page

alias python='arch -i386 /usr/bin/python[version]'

where version is of course your version.

If you are on windows i believe you can do similar as well, though I'm not sure how to alias commands in windows.

Community
  • 1
  • 1
Mike McMahon
  • 7,096
  • 3
  • 30
  • 42
  • I tried this and I dont get the `no matching architecture` anymore. But he doesn't find the pygame module: `Traceback (most recent call last): File "main.py", line 6, in import pygame ImportError: No module named pygame` – Philipp Apr 25 '12 at 07:23
0

After reading your three edits, it seems like there is an architectural problem. Since PyGame doesn't work on a 64-bit platform, you need to chose the 32-bit python interpreter in this case.

Go to Eclipse->Preferences->PyDev->Interpreters->Python Interpreter and add a new 32-bit python interpreter. The path for 32-bit python interpreter would most probably be the same as your usual python interpreter except that the file is called "python2.7-32" instead of "python2.7" (if the python version is 2.7). So, for me it is: "/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-32".

Once setup, you can either make it a default interpreter or chose it from Project->Properties->PyDev - Interpreter/Grammar when using PyGame.

HasnainMamdani
  • 134
  • 2
  • 11