Skip to content

Pygame for Android "longintrepr.h" file not found SOLUTION!

Kivy-Reloader

GitHub Repository

AI Transcript provided by KivyWhisper

Okay, hello and welcome back to Kivy School. Today we're going to be talking about building the Pygame module using buildozer on Windows. Basically there's this bug and the bug is that you're getting fatal error longintrepr.h not found. You can also see the problem here. Right, I'm getting an error longintrepr.h is not found, right?

So I'm going to show you I correctly built this guy's example game on my own Android phone. And as you can see, I won't even use my mouse. I'm going to click on it on my Android phone and as you can see it works.

For this I'm using scrcpy in order to cast the phone screen onto my Windows desktop. Okay, and you can see it works. So let's get started. Now let's edit this, edit this, edit this. The reference video is here so you can follow these instructions and then when you get to the bug you can come follow me but I'm going to do it directly from scratch, right? So what is the solution I've said? This works, this works.

You're going to say change the requirements on buildozer to 3.10.12, Kivy to 2.3.0, host Python to 3.10.12 and pyjnius to 1.5. And then now why does it work? Very quickly what's the problem is that Pygame has an issue when building with Python 3.11. The issue is this longintrepr.h is not found, right? That was the issue. They even have their own issue on it on GitHub but we're not going to deal with that.

Instead we'll just downgrade our Python and there this guy is choosing 3.10.12, right? So we downgrade our Python to 3.10.12. We completely avoid the problem. We didn't solve it, we just avoided the problem. Quick recap what happened getting this Pygame thing to work and now we're going to build from scratch.

Yeah let's get started. First thing you do is you need WSL and then you need to install these buildozer requirements, right? Okay so as you can see I have a blank folder. I'm in WSL2. You can't use one, you got to use two. I'm in WSL2 and now it says okay sudo apt update, right? So let's go. sudo apt update. My next sudo apt install all of these. Okay they're already installed because I've been building already for Android.

Then it says add the following line to your bash.rc. I've already added it and then here you don't need to do this. Actually what I'm going to do is in my virtual environment I'm going to specify cython is equal to 0.29.33. So that's it and let's keep going. So I'm going to go poetry init. So here I'm using poetry but you don't need to use poetry. You can just create your own virtual environment using the way you like. Just pressing enter okay poetry add. Just pressing enter okay poetry add. And then here I'm going to use kivy-reloader. Poetry add kivy-reloader. Then when you get kivy-reloader you also get kivy.

So we're going to copy the old code from the old game as well as the image. Copy paste save. And then here I got this image and right click reveal in file explorer paste like this. Now let's verify that it works. So I'm going to go poetry shell to enter the poetry shell. This is actually just my virtual environment. If you were to create your own virtual environment you do dot activate bat.activate using the python name.

Okay you need to add pygame so poetry add pygame. So let's run it and as you can see it's the same game now it works. So you can follow the original video guide. That's not the big deal. The big deal now is going to be building with buildozer.

So what was the fix? The fix was that you're going to set python3 to 3.10.12 kivy-reloader to 2.3 host python to 3 10 pyjnius to 1.5. So I'm going to do a little cheating and I'll do kivy reloader init. This will just create for me buildozer.spec. Maybe force refresh. You can see right here. Here it is. First what I'm going to do is I'm going to build correctly, go and code correctly, and then get the error.

So kivy run and then this is the same as saying buildozer -v android debug. Okay so I'm back. Now as you can see these are the requirements I'm using which you don't need all of them. You just need the rest of this for hot reloading. But right now let's just focus on python, kivy, and pygame right? With the naked python, kivy, pygame requirements I got the error the same error again and it's going to be if you scroll scroll up or down right here fatal error longintrepr.h file is not found right?

So that's the problem that most people get and again I've said it's because pygame has an issue when building with python3 11. Now let's apply the fix right? And the fix here was that we're going to say the python is equal to 3 10 so I'll just switch it to the correct one the one that works. So we need python is 3 10 so here I have our 3.10.12 it's the same,kivy 2.3 you have post python 3.10.12 pyjnius is 1.5.0 and as you can see I added pygame as well and then what next?

So here and also make sure one thing I was thinking about while I was building you should also make sure to install cython. One of the most common issues is that cython is not installed right? So you should just do if you use poetry or like any package manager I did poetry add cython or if you use pip you know the basic pip install cython right? And you just need cython installed into your virtual environment so that's it. So remember you need cython as well.

And now here's where you're at longintrepr.h file is not found okay, now it's built correctly. We do this next step we're going to say okay buildozer appclean and what that does is it deletes all of the buildozer files all the compiles then we're going to start again right? So I'll also do the buildozer build because I know not everybody is going to use kivy reloader. Let me just find the command here it is.

We'll use the actual buildozer command and then it's gonna build and then I'm gonna show you that it works and then I'll see you soon. Okay and then back and it built. So here's the command buildozer -v android debug deploy run and again we just downgraded our python to 3 10 so it will compile correctly and as you can see it's saying wait for application to start so actually on this other terminal I'm going to say scrcpy just to connect to my device and as you can see I'm my mouse is going to be here.

I'm not clicking on it. The default game that the original tutorial had -- now it works. So yeah so as long as you downgrade your python pygame should build and yeah that's it so thank you for watching. If you have any other questions make a comment or go to the discord and if you have some more problems we'll be glad to help you. All right this has been Kivy School thank you for watching!

Actually I forgot there's one more thing I need to do so I'm going to show you just in case you need some more help. I'm going to show you pip list what I've installed so here's my pip list I'm going to go slowly and then here's going to be my buildozer.spec the only thing I changed was requirements but if you need any more I'm just going to go slowly just slowly look and the rest is just commented out except for these these these log levels okay then I use scrcpy. Man all right that's it so thanks for watching again if you have any questions please let me know in the comments go to the kivy discord and ask your questions and good luck with your pygames. Show me what you got!

Article Error Reporting

Message @BadMetrics on the Kivy Discord.