Using a Python script in Lakka?

I would like to build something similar to the Game Girl, with Lakka installed on a Raspberry Pi.

To manage power and add a power button, I would like to use a GPIO module. Such modules require a Python script to initiate a clean shutdown when pressing the power button again.

How could I install Python on Lakka ? By recompiling it ?

I could also use Raspbian and just put RetroArch, but it wouldn’t have the SSH/Samba/WiFi/power management options.

Thanks for the help :slight_smile:

You can recompile it, or you can use bash instead of python

I’ll try to install Python and the systemctl power switch service directly in the ROM then !

How hard would it be to add Python to the ROM ? There is already a “python” package in the repo, should I just enable it ?

Yes, the Python package is there, you just add it in the list of the dependancies in packages/lakka/RPi2

I recompiled Lakka with the 2.1-dev branch (I was using the 2.0 release) and Python was there out of the box, looks like it was added in the meantime.

Yes it was added as a dependancy of SAMBA 4. But I will try to remove it in the future if possible. Not sure if it’s possible, though.

I don’t know the weight it would have on Lakka but you could also add the gpio command line utility from wiringPi and the RPi.GPIO Python library. I’m going to use them in my project so if you want me to make a PR just ask.

wiringPi is enabled on all our RPi images, you can copy the python library manually maybe?

In advance, sorry for the massive necro. Though as a new user it seems recommended to post replies on similar subjects while waiting for approval.

I’ve just downloaded Lakka through Github because I actually wanted to install Python 3 for the RPi 4 build. Problem is it fails at scripts/install ncurses. So I first wanted to know if I’m doing something wrong (I’ve been looking for the log as suggested, but there’s a lot of those files and folders called log, so do tell me if there’s a file I should share) ? Or is the build just failing right now (I know it happens for Github projects to get pushes that make builds fail but since Lakka doesn’t have such indicator in the README.MD I’d rather ask to be safe) ?

Other than this, it would seem Python 3 actually IS being built but when I imaged the last nightly, the only version I could find was the 2.7 (at least that’s what is reported by Python through SSH). I think it would be very beneficial for Lakka to have Python 3, and if it’s not already the case with this version of Python 3, include pip. There’s a lot of small project involving Lakka that could benefit from it and I think it doesn’t represent a big risk of user error or a big overhead in terms of size (could be wrong, correct me if so). The immediate that comes to mind and my current case is the Retroflag Nespi Safe Shutdown but another that comes to mind would be reading a battery level and displaying as an overlay for a portable Pi 4 console. But on-topic I’d like top know where I should make that suggestion.

As a more direct workaround, how would I go about enabling Python 3 when building Lakka myself for the RPi 4 and enable Python’s RPi.GPIO as well (which is apparently part of the add-ons within the repository).

Thanks a lot in advance :slight_smile:

The file you should share is simply the build log (the console output that you get when the failing package is built).

As for Python 3, you could use the Python package from LibreELEC which Lakka is based on: at master · LibreELEC/ (

This might work right out of the box, or require a bit of work, such as adding dependencies or updating dependent packages.

Also, Python is probably only built for the host, not for the target. This means Python is just being used as a helper tool to create the image, but it won’t be present anymore on the actual image that you install on your device. If that is the case, you would have to add “Python3” as a dependency somewhere in your project (there is a variable ADDITIONAL_PACKAGES in the file “distributions/Lakka/options” , this would be a possible place to put it).

Well that’s the thing, the package is clearly there, and the RPi 4 build clearly goes through the trouble of building it (there is in the build folder a folder name Python 3) but the RPï 4 project must specify somewhere at some point to use version 2, I just can’t find where that would be. I opened every options and config file, related to Pi or General configuration and found nowhere where that would be specified.

Hmm would that console log be output to a file by default ? If not I’ll just launch it again and upload the output !

Oh ok I get it now. The weird thing though is that RPi.GPIO is also part of add-ons, and this makes no sense to build only for the host, this is clearly a LibreELEC thing meant to support GPIO, but support is cut somewhere as well. I will look into that ADDITION_PACKAGES variable, possibly add-ons would work similarly.

In my particular case I only need RPi.GPIO but I still think Lakka would benefit from having pip to let users install python modules.

Sorry, please disregard what I said above. I didn’t know that Lakka already had the Python3 package. Currently, it seems to build Python2 for the host and target, and Python3 just for the host. Again, if you want Python 3 to be available on your target, you would have to add it somewhere, either as a dependency of another package, or if it’s not logically a dependency, as a plain addon package in the options file I mentioned above.

To log the build output you could use:

DISTRO=Lakka [...] make image | tee log.txt

In general, if you don’t understand what triggers a package to be built, open a terminal in the packages directory (Lakka/packages) and issue the following command:

grep -rnw -e 'packagename'

This will show you a list of all packages that trigger this package to be built (look for the lines starting with PGK_DEPENDS_). For example, the Samba package, which is part of Lakka, triggers Python 2 to be built. You’ll also see that currently, Python3 is built for the host only, this is because currently no other package needs it to be present on the target machine.

Hint: If a package has no machine target after its name, it defaults to target (“Python3:target” and just “Python3” are equivalent).

Oh boy do I feel dumb. It would seem I was running out of space of my virtual drive storage -_- So as far as the building error it shower one of the script failing, but fortunately when trying to run the script again today, storage failed at another point and the builder was actually able to tell me it was a storage issue. Should have guessed so when Linux kept warning me about low storage hmm hmm. Sorry about that one. As for Python I was able to pinpoint what you were telling me about the additional packages, so I put Python 3 and RPi.GPIO there, hoping it works.

Ah thanks a lot. Just to clarify (it’s been a LONG time since I’ve done some proper bash, and grep was never my strong suit anyway), this command will search for ‘packagename’ within all files recursively in the current folder ?

As for your hint, I guess changing Python3:host to Python3 in the PKG_DEPENDS_TARGET would also work for building Python automatically. That would be I assume a cleaner way was the Lakka team to add Python 3 on all platforms (especially considering additional packages is nearly empty in the options file). I will report on whether my attempts succeed.

I find it weird that the repos containing script for Lakka’s Retroflag safe shutdown never realized their scripts wouldn’t work :thinking: Oh well.

No, don’t do that. You shouldn’t modify any existing package for what you want to achieve. The “clean way” in this case is really adding it to your Lakka options file.

Yeah I figured that much when looking at all the possibilities afterward, thanks for clearing it up though :slight_smile:

Ok now I have a small issue. The compilation is going pretty well but it’s stuck on higan with that error though :

[281/346] [DONE] install handy
INSTALL      hatari (target)
[282/346] [DONE] install hatari
INSTALL      higan-sfc (target)
[283/346] [DONE] install higan-sfc
error: pathspec '.' did not match any file(s) known to git
CLEAN      higan-sfc-balanced
      * Removing /home/linuxdev/LakkaRebuild/Lakka-LibreELEC/build.Lakka-RPi4.arm-3.0-devel/higan-sfc-balanced-5e965d0 ...
UNPACK      higan-sfc-balanced
APPLY PATCH (common)      packages/libretro/higan-sfc-balanced/patches/higan-sfc-balanced-01-remove_openmp.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
|diff --git a/nSide/GNUmakefile b/nSide/GNUmakefile
|index 02493b6..228ba06 100644
|--- a/nSide/GNUmakefile
|+++ b/nSide/GNUmakefile
File to patch: 

And It’s asking me to input a filename. I don’t suppose this is normal as this is meant to be an automated job but with little to zero indication, after searching I couldn’t find what file is meant to be patched, and at this point, it could just as well be higan itself actually failing to build (though I doubt so as the way I understand it, OpenELEC’s package system goes and download a specific version to build).

Any idea what could have led to this ? Or how to fix it ?

Thanks in advance :slight_smile:

This can happen if the source files that Lakka has downloaded are corrupted because the download location does not exist anymore. Check if your build directory for the higan package (Lakka/ is empty directly after this error appears. If yes, this is the cause.

You can trigger a re-download for a package by deleting the folder Lakka/sources/[packagename]

If the files are there, the other likely cause is a version mismatch between the package and the patch. If packages are updated, the patches that are going to be applied might stop working because the files they are supposed to patch do not exist anymore. You can try to omit the patch by prepending a dot to its filename, or update the patch to work with the new package version.

In general, if any of the cores fail to build (which is quite likely) and you cannot move on, you can temporarily remove the core from the options file:

Lakka-LibreELEC/options at master · libretro/Lakka-LibreELEC (

Edit: Hmm, I have just tried to build the package in question and it successfully downloads and compiles for me. Did you modify the package? What branch of Lakka are you using? The current master version? This error can also happen if you mix an old Lakka version with newer packages and vice versa.

You were correct in your first assumption. I did find it strange to find the folder completely empty but I just assumed the patch might be the first part of the build and since it was stopped there nothing else happened. Deleting the source and restarting the compilation job fixed it as expected.

As for your questions, I’m using the main Lakka-LibreELEC branch on the current master version (well, technically not current, it’s now about a day and a half old).