How can I get pygame for Python3?

14,128

Solution 1


Thanks to Sergey's suggestion, this is how to get it working:
INSTALL
(1) Move to a directory where you want the source code to be downloaded to
(2) svn co svn://seul.org/svn/pygame/trunk pygame
    NOTE:  Be sure to use the svn method.  Simply downloading the pygame*.tar.gz
           file from the pygame downloads page didn't work!
(3) cd pygame
(4) python3 config.py
    NOTE:  This confirms that you have the dependencies.
(5) python3 setup.py build
(6) sudo python3 setup.py install
    NOTE:  On my machine, I have the distro's python3.2 installed (which is in
           the /usr/lib directory).  This step places the pygame module into
           /usr/local/lib -- which is what you want (per Sergey's suggestion).

TEST
(1) python3
(2) At the '>>>' prompt, type "import pygame"
    VALIDATION:  If you get another '>>>' prompt, all is well.

per BlaXpirit, you may also choose to use hg instead of svn:

hg clone https://bitbucket.org/pygame/pygame

Solution 2

From Pygame wiki:

Does Pygame work with Python 3?

Yes. Pygame 1.9.2 supports Python 3.2 and up. Only the orphaned _movie module (not built by default) does not.

However, there seems no pre-packaged Pygame packages for Python 3 in Ubuntu repositories, at least as of 14.04.

I would suggest you to get the source packages from the pygame website and install it locally into a virtualenv or buildout. Globally installing python modules in evil anyway :) Here are the instructions: http://www.pygame.org/wiki/CompileUbuntu

Alternatively you can try this PPA: https://launchpad.net/~thopiekar/+archive/ubuntu/pygame

Solution 3

Someone needs to make a python3-pygame package that does this, but no one has yet

sudo apt-get install mercurial python3-dev python3-numpy libav-tools \
    libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
    libsdl1.2-dev  libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev
hg clone https://bitbucket.org/pygame/pygame
cd pygame
python3 setup.py build
sudo python3 setup.py install

Solution 4

Just use the below command to install pygame for Python3.

pip3 install pygame

It could install pygame correctly on Ubuntu 16.04 and Python Python 3.5.2.

Share:
14,128

Related videos on Youtube

TheGeeko61
Author by

TheGeeko61

After graduating high school in 1980, and earning my B.S. in Computer Science from Purdue University in 1986, I traveled to Hawai`i to relax. After a decade in the islands building my career and, more importantly, learning of the impractical affects on modern day life resulting from bully-ish behavior of the 18th and 19th century colonialists, I returned to the continent. Having worked for several startups around the country (including a successful one in Silly Valley), I have a yearning for techno-knowledge... of all types.

Updated on September 18, 2022

Comments

  • TheGeeko61
    TheGeeko61 almost 2 years

    There is a package (python-pygame) for Python2 available from the universe repository. However, I want to work through the tutorial in the Invent with Python book. Going through SPM (Synaptic), I cannot find a pygame resource for Python3.

    Also, I looked on the Pygame website and it is not clear if Pygame is available for Python3 (though the book indicates that it is).

    Can someone help me with my dilemma?

    • Oleh Prypin
      Oleh Prypin over 12 years
      IMPORTANT_MOVED.txt seems... important. So I changed the svn... line to hg clone https://bitbucket.org/pygame/pygame
    • fouric
      fouric over 10 years
      Try this answer on Stack Overflow. It worked perfectly for me (minus the part where I forgot to copy and paste the apt-get command with the dependencies and had to hunt down and install them by hand).
  • TheGeeko61
    TheGeeko61 over 12 years
    Thanks for the suggestion! I have posted the steps in the original question for an explicit answer.
  • Oleh Prypin
    Oleh Prypin over 12 years
    @TheGeeko61: I think you should post that as an answer, it's not "bad" in any way.
  • TheGeeko61
    TheGeeko61 over 12 years
    Alright, I'm doing so...
  • Jonathan
    Jonathan almost 9 years
    No longer up to date
  • Sergey
    Sergey almost 9 years
    @JonathanLeaders: It wasn't THAT much out of date: there are still no pre-compiled packages and you still have to install from source. I've added a few links to the answer though.
  • Rajalakshmi
    Rajalakshmi over 3 years
    On 18.04 I had to replace libav-tools with ffmpeg but that did the trick.