Using pygame on KDE neon

Hi, it looks like the versions of SDL and pygame in KDE neon are not compatible. This means games using pygame don’t work.

To reproduce, run the following in invent-registry.kde.org/neon/docker-images/all:user

neon@9903ad8760fc:~$ sudo apt install pygame
[...]
neon@9903ad8760fc:~$ python3 -c 'import pygame;pygame.init()'
pygame 2.1.2 (SDL 2.28.5, Python 3.10.12)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: SDL compiled with version 2.0.20, linked to 2.28.5
neon@9903ad8760fc:~$ 

Do you plan on fixing this?

kind regards,
Marcin

Where are you getting it from?
I don’t have it, using just ‘pygame’

$ sudo apt install pygame
[sudo] password for claydoh:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package pygame

there is python3-pygame provided by Ubuntu, though being 22.04 it is probably a bit outdated, and not something neon can ‘fix’ here.

Pygame prefers one install it using pip, which gets you current versions, and I assume matching/supported SDL2 libraries.

Thanks for a quick response, @claydoh !

:man_facepalming: that was a mistake in copy-pasting. I actually installed with sudo apt install python3-pygame which you also mentioned.

Well, the RuntimeError is partially because neon includes a newer SDL than what pygame expects:

neon@057e3460680d:~$ apt policy libsdl2-2.0-0
libsdl2-2.0-0:
  Installed: 2.28.5+dfsg-2+22.04+jammy+release+build2
  Candidate: 2.28.5+dfsg-2+22.04+jammy+release+build2
  Version table:
 *** 2.28.5+dfsg-2+22.04+jammy+release+build2 500
        500 http-archive-neon-kde-org/user jammy/main amd64 Packages
        100 /var/lib/dpkg/status
     2.0.20+dfsg-2ubuntu1.22.04.1 500
        500 http-archive-ubuntu-com/ubuntu jammy-updates/main amd64 Packages
     2.0.20+dfsg-2build1 500
        500 http-archive-ubuntu-com/ubuntu jammy/main amd64 Packages

(URLs mangled by myself to please discuss censorship.)

So if it is possible to provide a newer SDL, then perhaps it is possible for neon to include a newer pygame as well?

That could be an option :thinking: although I’m not sure if the existence of system-provided SDL would not be an obstacle here…

If I understand correctly, launching a python script inside a venv will only use whatever is available in the venv first and if that doesnt exist, it looks for system files.

So as long as pip installs the required SDL stuff into the venv, there should not be a conflict.

They won’t, as it isn’t related to Plasma. They don’t touch very much outside of that.

I believe that it does.

It seems to install to ~/.local/lib/ when not using a venv and it works! I just needed to sudo apt install python3-pip first.

Thanks for the help everyone!

1 Like

If you can, mark this as a solution so anyone else finding this will see it immediately :slight_smile:

1 Like

FTR, the exact commands were:

sudo apt install python3-pip
python3 -m pip install -U pygame --user

To verify it works:

python3 -c 'import pygame;pygame.init()'

To wipe the broken system-provided pygame:

sudo apt purge python3-pygame
1 Like