Installed Pygame, but Python claims it does not exist

11,360

The default python 2.7 on 14.04 is 2.7.6:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2

So I think that you installed your own python version which does not see the modules installed by apt-get.

Try instead to call python this way (the version installed in /usr/bin):

$ /usr/bin/python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> 
Share:
11,360

Related videos on Youtube

PaulMag
Author by

PaulMag

Updated on September 18, 2022

Comments

  • PaulMag
    PaulMag over 1 year

    I want to use pygame, but I am having trouble installing/using it. It appears to be installed, but Python cannot find it. I know there are several similar questions about this, but none of them gave an answer that worked for me.

    ​I used ​sudo apt-get install python-pygame. ​The installation appeared to complete successfully.​ ​When I redo it I am told that I have the newest version, so that should be alright.

    S​till, this happens:

    >>> import pygame
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named pygame
    

    ​ ​When I look for information I find on AskUbuntu that some people have a similar problem, but the only answer I could find was that they had been using Python 3, and that had caused the problem. ​I am using Python 2.7 (I tried to import in both python2 and python3, but no luck.

    Then I tried compiling myself according to the instructions here: http://www.pygame.org/wiki/CompileUbuntu I got this message:

    Package ffmpeg is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    
    E: Package 'ffmpeg' has no installation candidate
    

    So ​I removed ffmpeg and did everything else, which seemed to work.​ Running sudo python setup.py install did lots of stuff and did not throw any errors or warnings that I could see. But when it was finished, it is still impossible to import pygame.

    I also found something about 32 bit vs 64 bit problems. Could that be it? In which case, how can I install the correct pygame version when sudo apt-get doesn't know it? These related questions made me think it might be a 32/64-bit-issue (they are about Pygame on other OS than Ubuntu):

    ​My Python version:

    Python 2.7.8 |Anaconda 2.0.1 (64-bit)| (default, Jul  2 2014, 18:08:02) 
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
    

    OS: Ubuntu 14.04​LTS​, 64-bit

    UPDATE:

    Pygame works when I use /usr/bin/python and thus run this version of Python instead:

    Python 2.7. (default, Mar  22 2014, 22:59:56) 
    [GCC 4.8.2] on linux2
    
    • PaulMag
      PaulMag over 9 years
      @MadMike I added this information, and it seems Sylvain Pineau had the correct answer. My Anaconda version of Python seems to be 64-bit. It doesn't say what the 'normal', but I guess it might be 32-bit then. Not sure though.
  • PaulMag
    PaulMag over 9 years
    That's it, running Python like that fixed it! But should not version 2.7.8 be backwards compatible with 2.7.6? Pygame claims to be compatible with versions (2.7 <= x < 2.8). The third digit is only supposed to be backwards compatible patches/bugfixes. It feels very strange to have to use an older version of Python like this.
  • MadMike
    MadMike over 9 years
    I don't think this is a compatibilty issue between python version or 32 vs 64-bit. I rather suspect that the "other" python sets it paths on where to look for packages differently than the ubuntu-python does. You can fire up both python versiosn and do a "import sys; print(sys.path)" and compare the result.