Python >> Tutoriel Python >  >> Python GUI >> Pygame GUI

Comment puis-je obtenir pygame pour Python3 ?

Depuis le wiki Pygame :

Pygame fonctionne-t-il avec Python 3 ?

Oui. Pygame 1.9.2 prend en charge Python 3.2 et versions ultérieures. Seul le module _movie orphelin (non construit par défaut) ne le fait pas.

Cependant, il semble qu'il n'y ait pas de packages Pygame pré-emballés pour Python 3 dans les référentiels Ubuntu, du moins à partir de 14.04.

Je vous suggère d'obtenir les packages source sur le site Web de pygame et de les installer localement dans un virtualenv ou un buildout. Installer globalement des modules python dans le mal quand même :) Voici les instructions :http://www.pygame.org/wiki/CompileUbuntu

Sinon, vous pouvez essayer ce PPA :https://launchpad.net/~thopiekar/+archive/ubuntu/pygame


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.

par BlaXpirit, vous pouvez également choisir d'utiliser hg au lieu de svn :

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


Quelqu'un doit faire un python3-pygame package qui fait cela, mais personne ne l'a encore fait

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

Prochain article