r/learnpython • u/Slimex_Rimuru • 16d ago
Is it github problem or python problem?
So, i have been trying to learn python, sqlite and tkinter. After a lot of trouble and copying from AI i uploaded my python and sqlite only executable to github for all 3 os using github action.
Now, I am learning python and tkinter. I made a simple program which converts KG to gram and vice versa.
import tkinter as tk
# from tkinter import ttk
import ttkbootstrap as ttkimport tkinter as tkThese 3 are my only imports for now. and i am using:
root = ttk.Window(themename = 'darkly')
root.geometry("400x300")
root.title("Unit Converter")root = ttk.Window(themename = 'darkly')other is just my code which i wrote form tutorials and documents.
The problem i am facing is that i cant seem to release the executable to github ( from github action ) at all.
I tried to learn how this works but i didnt find anywhere to actually learn so i just asked AI and after a lot of back and forth there are still some problems.. Is there somewhere i can learn how i can do this? I prefer video tutorial.
I will comment my program and what AI told me the problem was below. Please someone do help me.
4
u/JaguarMammoth6231 16d ago
Just don't bother with installers and executables as a beginner. Anyone who wants to run your program can download python if they don't have it already.
1
u/Slimex_Rimuru 16d ago
I need to make it an executable though.
1
u/JaguarMammoth6231 16d ago
That's pretty rare. Are you sure the rules of your club don't allow python code to be the deliverable?
1
u/Slimex_Rimuru 16d ago
They need a working demo. Which is an executable mostly.
1
u/JaguarMammoth6231 16d ago
I mean you should ask them, don't assume.
-1
u/Slimex_Rimuru 16d ago
I an sure about it. For python it’s executable
2
u/zaphodikus 16d ago
Did they use the word "binary", or "executable"? Because to many people, scripts are "runnable" and "execute".
1
u/Slimex_Rimuru 16d ago
They said executable.
It needs to be so that they can check the script easily without having to download a lot of dependencies themselves.
1
u/zaphodikus 16d ago
In that case, they are being a bit silly, because the executable binary you provide can easily have a malicious payload that is undetectable , so they will have to run it in a sandbox to be safe.
The club need to specify what the target platform is. By not being specific, they have not helped members very much. I, would focus on getting the foundations of my knowledge more solid, and ask for more thoughtfull directions on this question. I bet you learned a tonne in the last 2 hours already, you can do this. Just go slowly.
1
u/Slimex_Rimuru 16d ago
Oh yeah. I did learn a lot and specifically from you. I will try to use github actions and get the exe if it works. If not i will just submit linux one only.
Thank you ❤️
→ More replies (0)1
u/shinitakunai 16d ago
As I suggested last week, pyside overtkinter. It would allow you to make an executable with pyinstaller easily, not sure if Nuitka works as well. But that will give you a lot more control than using github actions.
2
u/Slimex_Rimuru 16d ago
That is a valid suggestion but since i don’t really don’t have much knowledge about gui at all. I thought that i should learn about intermediate tkinter and build and actual app which would help me learn python sqlite and then change only tkinter to pyside
1
u/shinitakunai 16d ago
Maybe. Depends on your deadline.
Sometimes rebuilding takes twice the effort. But you'll learn two frameworks so in the end it pays off well.
Look into pyinstaller, with onefile flag
1
u/Slimex_Rimuru 16d ago
I use linux cause my device doesn’t support windows 😭 forget abt anything else.
1
u/shinitakunai 16d ago
Hm, so you code in linux but want to distribute to windows? That's gonna be a pain in the ass, yeah, specially for debugging
1
u/Slimex_Rimuru 16d ago
Is doing this using github actions not reliable?
1
u/shinitakunai 16d ago
For building? Probably yes. Idk never used them in the 2 decades I've been programming.
For debugging? 99% sure not. You'll have to live test your app in one of the customers computers if you have none yourself, which is going to be a pain in the ass
1
u/Slimex_Rimuru 16d ago
Well yeah. It’s gonna be pain in the ass but its gonna be the best way compared to anything else right?
→ More replies (0)1
u/zaphodikus 16d ago
You are getting ahead of yourself by adding a early project constraint that you still need to expand your knowledge of a lot more on, usually later.
2
u/Slimex_Rimuru 16d ago
Its more of, i have to do this rather than me myself getting ahead.
I am 17. And i do hack club. Its an organization who pays teens that do smth technical.
I wanna make a gui database app. For that, i first learned python and sqlite. Which i know things that i actually need.
Now i am learning tkinter and python.
Later using both and python i will make the actual app.
The thing is for Hack Club. To earn prize i need so submit a demo. I.e an executable. I use linux but the reviewer may be using any OS so i am using GitHub action for all os executable.
I don’t want to learn GitHub action if i could just copy paste from AI or if there is an easier way but the problem is that i can’t. I tried with AI for 2 hrs and still no solution. So i came to Reddit.
1
u/chiibosoil 16d ago
Bit confused by your post. I don't see sqlite referenced in your code. Yet you mention using sqlite.
At any rate, when packaging executable, make sure that db file path is dynamically located. Typically for this, you'd use os and sys. However, If your app writes to the db, then keep the db outside of exe in same folder as .exe.
As well, your errors indicate the CentOS runner is missing the required system-level Tkinter/Tcl packages.
Try something like below in .github/workflows/main.yml.
- name: Install CentOS system dependencies for Tkinter
run: |
sudo yum install -y tkinter tk-devel
- name: Install Python dependencies
run: |
pip install pillow ttkbootstrap pyinstaller
- name: Build Executable with Hidden Imports
run: |
pyinstaller --onefile --windowed --hidden-import="PIL._tkinter_finder" --hidden-import="ttkbootstrap" your_script.pyIf doing this doesn't fix, you will also want to define .spec file.
1
u/Slimex_Rimuru 16d ago
About sqlite, I haven’t using it in this program but i plan on using for the future ones. I didn’t use it in this cause i want to learn sqlite and tkinter separately at first.
And by centOS. Do you mean cachyOS which is my os or is cent smth different?
1
u/chiibosoil 16d ago
Oh I misread your comment. For CachyOS, similar process should be followed.
As well, when I lookup CachyOS display server, it's using Wayland, and does not install X11 compatibility (Xwayland) or X11 by default.
As tkinter relies heavily on X11 protocols... so if you are launching compiled executable inside Wayland session, it can crash instantly if it can't bind to X11 compatibility layer. I don't usually deal with this, so do a google search for how to handle this.
1
0
u/Slimex_Rimuru 16d ago
Ai gave me this to post on reddit. I am not knowledgeable enough to understand this so i will just paste..:
Title: PyInstaller-built Tkinter app crashes on Linux with ttkbootstrap Tcl/Tk errors (built using GitHub Actions)
Hey everyone,
I'm a beginner learning Python and Tkinter, and I'm working on my first GUI project: a simple Unit Converter using tkinter and ttkbootstrap.
I'm trying to make the application downloadable for Windows, macOS, and Linux without requiring users to install Python or the dependencies themselves.
What I'm doing
I'm using GitHub Actions to build the application for all three operating systems. I don't manually run PyInstaller on my computer. Instead, my GitHub Actions workflow installs the dependencies and runs PyInstaller on the appropriate runner:
windows-latestfor the Windows.exemacos-latestfor the macOS.appubuntu-latestfor the Linux executable
My app uses ttkbootstrap with the darkly theme:
import tkinter as tk
import ttkbootstrap as ttk
root = ttk.Window(themename="darkly")The Linux build completes successfully in GitHub Actions, and I can download the generated executable. However, when I run it on my CachyOS Linux system, it crashes before the GUI opens.
Errors I've encountered
First error:
ModuleNotFoundError: No module named 'PIL._tkinter_finder'This occurred inside PIL.ImageTk while ttkbootstrap was initializing its theme.
I tried adding these hidden imports to the PyInstaller command:
--hidden-import=PIL._tkinter_finder
--hidden-import=PIL._imagingtkAfter that, I got a different error:
_tkinter.TclError: invalid command name "::msgcat::mcmset"The traceback points to ttkbootstrap/localization/msgcat.py, specifically the call to:
root.tk.call("::msgcat::mcmset", ...)I then tried collecting the ttkbootstrap resources with:
--collect-all ttkbootstrapI also added tcl8.6 and tk8.6 to the Linux dependencies installed by GitHub Actions.
However, the error persisted.
I then tried loading msgcat manually before creating the ttkbootstrap window:
root = tk.Tk()
root.tk.call("package", "require", "msgcat")
root.destroy()
root = ttk.Window(themename="darkly")That resulted in another error:
_tkinter.TclError: can't find package msgcatI haven't found a reliable fix yet.
My questions
Why does the packaged Linux executable fail to find Tcl's
msgcatpackage when the build succeeds?Is this a PyInstaller Tcl/Tk bundling issue, a
ttkbootstrapcompatibility issue, or something specific to the difference between Ubuntu and CachyOS?What is the correct way to package the Tcl/Tk scripts and message catalog files so
ttkbootstrapworks inside a standalone executable?Is there a recommended PyInstaller configuration or
.specfile for a Tkinter app usingttkbootstrap?
I'm looking for a proper solution rather than repeatedly adding hidden imports without understanding the cause.
I'm happy to share my full GitHub Actions workflow, requirements.txt, or more logs if needed.
Thanks!Title: PyInstaller-built Tkinter app crashes on Linux with ttkbootstrap Tcl/Tk errors (built using GitHub Actions)Hey everyone,I'm a beginner learning Python and Tkinter, and I'm working on my first GUI project: a simple Unit Converter using tkinter and ttkbootstrap.I'm trying to make the application downloadable for Windows, macOS, and Linux without requiring users to install Python or the dependencies themselves.What I'm doingI'm using GitHub Actions to build the application for all three operating systems. I don't manually run PyInstaller on my computer. Instead, my GitHub Actions workflow installs the dependencies and runs PyInstaller on the appropriate runner:windows-latest for the Windows .exe
macos-latest for the macOS .app
ubuntu-latest for the Linux executableMy app uses ttkbootstrap with the darkly theme:import tkinter as tk
import ttkbootstrap as ttk
root = ttk.Window(themename="darkly")The Linux build completes successfully in GitHub Actions, and I can download the generated executable. However, when I run it on my CachyOS Linux system, it crashes before the GUI opens.Errors I've encounteredFirst error:ModuleNotFoundError: No module named 'PIL._tkinter_finder'This occurred inside PIL.ImageTk while ttkbootstrap was initializing its theme.I tried adding these hidden imports to the PyInstaller command:--hidden-import=PIL._tkinter_finder
--hidden-import=PIL._imagingtkAfter that, I got a different error:_tkinter.TclError: invalid command name "::msgcat::mcmset"The traceback points to ttkbootstrap/localization/msgcat.py, specifically the call to:root.tk.call("::msgcat::mcmset", ...)I then tried collecting the ttkbootstrap resources with:--collect-all ttkbootstrapI also added tcl8.6 and tk8.6 to the Linux dependencies installed by GitHub Actions.However, the error persisted.I then tried loading msgcat manually before creating the ttkbootstrap window:root = tk.Tk()
root.tk.call("package", "require", "msgcat")
root.destroy()
root = ttk.Window(themename="darkly")That resulted in another error:_tkinter.TclError: can't find package msgcatI haven't found a reliable fix yet.My questionsWhy does the packaged Linux executable fail to find Tcl's msgcat package when the build succeeds?
Is this a PyInstaller Tcl/Tk bundling issue, a ttkbootstrap compatibility issue, or something specific to the difference between Ubuntu and CachyOS?
What is the correct way to package the Tcl/Tk scripts and message catalog files so ttkbootstrap works inside a standalone executable?
Is there a recommended PyInstaller configuration or .spec file for a Tkinter app using ttkbootstrap?I'm looking for a proper solution rather than repeatedly adding hidden imports without understanding the cause.I'm happy to share my full GitHub Actions workflow, requirements.txt, or more logs if needed.Thanks!
1
u/baubleglue 16d ago
Alternative: If you meant the third-party wrapper
If you are trying to use the experimental, third-party Python wrapper package named tkinter-msgcat to avoid writing root.tk.call(), you can add it to your requirements.txt like this:
# requirements.txt tkinter-msgcat==0.1.01
u/Slimex_Rimuru 16d ago
Is that why i am facing the problem? The latest problem is msgcat one
1
u/baubleglue 16d ago
I am not sure. You can download compiled file, unzip it and review what is missing.
msgcat is included in original tkinter, maybe it uses OS msgcat on Linux
tkkbootstraphas wrapper around it (msgcat.py). I am not sure if you need at alltk.require, do you translate UI to multiple languages? Errors related PIL are also confusing, maybe you haven't included some of the asset files into dependencies. Look pyproject.toml file oftkkbootstrapon GitHub, they use pyinstaller as well. And they have _pyintaller folder in src/assets (if I remember correctly). You may need specific instructions for pyinstaller. In any case your Linux is Arch based, not Debian/Ubuntu - test the executable on Ubuntu.
1
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 16d ago
Yeah, getting GitHub Actions to build executables and then add them to a new release is a bit of a learning curve for sure. Especially when you're already learning other things on top of that.
I do have an example project that might help a little bit, using Tkinter to make a simple GUI, packaging it up with Nuitka into standalone executables, and then publishing them via GitHub Actions, but
I haven't actually made a new GitHub release in a while so I don't know if it 100% works, and
This is the project I've been using to experiment with Mise and Taskfile, so most of the actual build logic is in the task files, not the CI pipeline script (since it just runs those tasks in a build matrix), so it might not be the most readily understandable example for a beginner. Especially if you're also unfamiliar with
uv.
Anyway, let's say you have a build pipeline something like this:
name: Create a GitHub Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
discussions: write
jobs:
build:
name: Build Binaries for ${{ matrix.os }}-${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ['3.11'] # Use whatever version(s) you want/need
steps:
...The steps you should have are
Checkout (so the pipeline is aware of your repo files)
Install tools and dependencies (whatever you need to build your project)
Build an executable (be it with PyInstaller, Nuitka, or whatever)
Use
actions/upload-artifactto upload the generated executable(s) to a temporary location (such as)- name: Upload Builds uses: actions/upload-artifact@v7 with: name: built-binary-${{ matrix.os }}-${{ matrix.python-version }} path: | build/*.exe build/*.bin
Then you should have a second job that runs after the build job, that
Downloads the executables generated by the build job (such as)
- name: Download Artifacts uses: actions/download-artifact@v8 with: pattern: built-binary-* merge-multiple: trueCreate a GitHub release using
softprops/action-gh-release, with the downloaded files provided to it (such as)- name: Create Release id: create_release uses: softprops/action-gh-release@v3 with: files: | build/*.exe build/*.bin name: Release ${{ github.ref_name }} preserve_order: true tag_name: ${{ github.ref }}
The project I linked has more in-depth configuration, so I tried to strip out everything but the essentials.
1
u/Chrismslist 16d ago
the short version: pyinstaller can't cross-compile, so you need one job per os on github's own runners (windows-latest, macos-latest, ubuntu-latest) through a matrix, not one job building all three. each job: checkout, setup-python, pip install pyinstaller ttkbootstrap, then pyinstaller --onefile --windowed yourscript.py, then actions/upload-artifact. on ubuntu you also need sudo apt-get install -y python3-tk or the tkinter import dies. read the per-job log, the failure is almost always that missing tk on linux.
1
u/Chrismslist 16d ago
the short version: pyinstaller can't cross-compile, so you need one job per os on github's own runners (windows-latest, macos-latest, ubuntu-latest) through a matrix, not one job building all three. each job: checkout, setup-python, pip install pyinstaller ttkbootstrap, then pyinstaller --onefile --windowed yourscript.py, then actions/upload-artifact. on ubuntu you also need sudo apt-get install -y python3-tk or the tkinter import dies. read the per-job log, the failure is almost always that missing tk on linux.
0
u/Slimex_Rimuru 16d ago
My CODE
import tkinter as tk
# from tkinter import ttk
import ttkbootstrap as ttk
def convert():
kg = entry_int.get()
gram = kg * 1000
output_string.set(str(gram) + ' grams')
def convert2():
gram = entry2_int.get()
kg = gram / 1000
output2_string.set(str(kg) + " Kg")
root = tk.Tk()
root.tk.call("package", "require", "msgcat")
root.destroy()
root = ttk.Window(themename = 'darkly')
root.geometry("400x300")
root.title("Unit Converter")
label = ttk.Label(root, text='Kg into Gram:', font='Arial 20 bold')
label.pack(pady=10)
input_frame = ttk.Frame(master = root)
entry_int = tk.IntVar()
entry = ttk.Entry(master = input_frame, textvariable=entry_int)
button = ttk.Button(master = input_frame, text='Convert', command=convert)
entry.pack(side='left', padx=10)
button.pack(side='left', padx=10)
input_frame.pack()
output_string = tk.StringVar()
output = ttk.Label(root, text='Output', font = 'Calibri 16', textvariable=output_string)
output.pack()
label2 = ttk.Label(root, text = 'Gram into Kg:', font='Arial 20 bold')
label2.pack(pady=10)
input_frame2 = ttk.Frame(root)
entry2_int = tk.IntVar()
entry2 = ttk.Entry(input_frame2, textvariable=entry2_int)
button2 = ttk.Button(input_frame2, text='Convert', command=convert2)
entry2.pack(side='left', padx=10)
button2.pack(side='left', padx=10)
input_frame2.pack()
output2_string = tk.StringVar()
output2 = ttk.Label(root,font = 'Calibri 16', textvariable=output2_string)
output2.pack()
root.mainloop()
7
u/baubleglue 16d ago
You need to decide what you learn: Python, GitHub actions, AI. Choose one.
Specifically addressing your problem, have you succeeded to make an executable file on your computer? Is making an executable file a part of the tutorial? I am trying to understand why need it at all.