views:

45

answers:

1
+1  Q: 

pygame not found

Hello. I am running in ubuntu and I can code in python, without problem. I have tried to install pygame and to do make it so, I did:

sudo apt-get instal python-pygame

When I go into the python IDLE and write:

import pygame

I get:

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named pygame

What can I do to solve this problem? I am forgetting something, or doing something wrong?

+2  A: 

apt-get will install pygame for the registered and pygame-package-supported Python versions. Execute

ls -1 /usr/lib/python*/site-packages/pygame/__init__.pyc

to find out which. On my old debian system, that prints

/usr/lib/python2.4/site-packages/pygame/__init__.pyc
/usr/lib/python2.5/site-packages/pygame/__init__.pyc

That means if I'm not using either Python 2.4 or Python 2.5, pygame will not be available. The Python version your IDLE is using should be displayed at the top (you can also see it with import sys; print(sys.version)).

You can either manually install pygame or try to add the installed version with

import sys
sys.path.append('/usr/lib/python2.5/site-packages/')
import pygame

Depending on the complexity of the loaded module(pygame in your case), this might cause some problems later though.

phihag
This work, yes! Is there a way to fix this so I don't need to write:> sys.path.append('/usr/lib/python2.5/site-packages/')
petermlm
@petermlmAs I said, you could try installing it yourself (and should do so if you plan to deliver it to other people). If it's just the typing that bothers you, you can also start a command line terminal, go to the directory you're executing idle in (import os; print(os.getcwd())) and create a symlink with ln -s /usr/lib/python2.5/site-packages/pygame.Btw, if my answer solves your question, consider marking it as accepted so other people know they'll find an answer here.
phihag
Yes, it worked like you said! Thank you very very must!
petermlm