Installing pygame on Raspberry PI3B with openHAB OS

  • Platform information:
    • Hardware: Raspberry PI3B
    • OS: Specific purpose OS openHAB
    • openHAB version: 4.1.1
  • Issue of the topic: please be detailed explaining your issue

I successfully installed the specific purpose OS openHAB on a PI3B. This works fine.
But now I want to add a python script giving audio output, alarm etc. For this I need the pygame module in Python. I tried installing pygame from commandline using
“sudo apt-get install python-pygame”
But this gives an error:
“Package python-pygame 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”.
I also tried
“sudo pip3 install pygame”
This looks better: “Successfully installed pygame-2.5.2”
But when executing the py-script the import of pygame gives an error:
"File “/usr/local/lib/python3.9/dist-packages/pygame/”, line 92, in from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ImportError: cannot open shared object file: No such file or directory"

How to move onwards. How to succesfully install pygame?

You will likely find better support on the pygame repo or a generic python or Raspberry Pi forum. None of this has anything to do with openHAB nor openHABian so few if anyone here will be able to help.

Thank you for this reply. I will follow the link. I will let you know when I succeeded. May take some time.

use a virtual environment

No Python expert - but that could be an permission issue. You stated that you installed the module using sudo - and I guess when using the module you do not run in root context?

As mentioned - you might use a Python virtual environment (venv) to install the package and run your script. Or - if you want to install the package globally - look into how to do that with user permissions :thinking:

Thank you Felix. I will try the venv. I don’t know whether it is a permission issue. I installed other modules and that was succesful.

seems that a required share library from an other package is missing.
If you use a search engine to search for that error message you should get some hints.

I exactly followed the documentation “Installing python modules”. But with the same outcome. Installing other modules were succesful. So to solve the problem I switched to another audio module pydub. With succes.
Thanks for the comments.