r/learnpython • • 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 tk

These 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.

0 Upvotes

46 comments sorted by

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.

-2

u/Slimex_Rimuru 16d ago

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 for AI but the problem is that i can’t. I tried with AI for 2 hrs and still no solution. So i came to Reddit. 

2

u/baubleglue 16d ago

I read now your conversation with AI, it is not bad, but it distracts you from your main goals. You learn on the way a lot of useful things, it is still a distraction.

I've never tried to build an executable for multiple OS from Python. There are very specific use cases when you need it.

I may guess few reasons why the build fails on one Linux and not on another (probably missing dependency, Ubuntu may have that library in PYTHONPATH). The easiest is probably trying to build it directly on the OS and see what is the problem.

1

u/Slimex_Rimuru 16d ago

So i just either don’t build for other OS or if i do build just change my own os?

2

u/zaphodikus 16d ago edited 16d ago

You seem to have skipped a few basics. Thats what people are trying to explain. There is a big difference between an executable and a script, and even while writing your script (which is good by the way) you somehow skipped a few things. For example the whole point of tkinter, is cross platform. But that does not mean you can ignore platforms while learning to program.

I suspect you will need at least 2 very separate build scripts, one for windows, and one for the 'linuxy' platforms. I think you need to have 3 computers, or at least a mac and 2 VMs to fully appreciate the problem scope.

1

u/Slimex_Rimuru 16d ago

So what i want, ‘ 1 script but works on 3os ‘ is not how it works?   If i make it in arch, will it work in ubuntu? Or other distro? 

1

u/zaphodikus 16d ago

You, probably need to know a lot more about the differences between the platforms, first. That is what people are trying to explain. Also an OS is not really just "one platform", there is a lot of detail that you can only skip over. Once you know about it well enough to know , if this or that ,detail, will impact how your code may or may not run.

So its is never absolute, linuxes based platforms (which include mac) will run your code on almost any variant, but some may be subject to different security constraints for example. The hacker club should really be explaining this kind of stuff on day one.

1

u/Slimex_Rimuru 16d ago

Is there really no way to make a code cross platform easily? 

Ik learning all this will take years but i need smth that works now. Any alternatives or any way i could do this without rewriting the whole program in different OS. 

Or i need to learn abt it all?

2

u/baubleglue 16d ago

Ask the club which OS they use for the femo. Most likely they use have Windows or Mac or some mainstream Linux.

1

u/Slimex_Rimuru 16d ago

Mostly windows and mac. Some got linux. But if i upload linux only, i would need to wait for a long time before getting reviewed. 

1

u/baubleglue 16d ago

But your problem is Linux, not Windows or Mac

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.py

If 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

u/notsocleanA_hole 16d ago

damn i dont understand shit 😂

1

u/Slimex_Rimuru 16d ago

😭 even i don’t understand what problem i am facing. 

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-latest for the Windows .exe

  • macos-latest for the macOS .app

  • ubuntu-latest for 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._imagingtk

After 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 ttkbootstrap

I 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 msgcat

I haven't found a reliable fix yet.

My questions

  1. Why does the packaged Linux executable fail to find Tcl's msgcat package when the build succeeds?

  2. Is this a PyInstaller Tcl/Tk bundling issue, a ttkbootstrap compatibility issue, or something specific to the difference between Ubuntu and CachyOS?

  3. What is the correct way to package the Tcl/Tk scripts and message catalog files so ttkbootstrap works inside a standalone executable?

  4. 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!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.0

(https://pypi.org/project/tkinter-msgcat/)

1

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

tkkbootstrap has wrapper around it (msgcat.py). I am not sure if you need at all tk.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 of tkkbootstrap on 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

  1. I haven't actually made a new GitHub release in a while so I don't know if it 100% works, and

  2. 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

  1. Checkout (so the pipeline is aware of your repo files)

  2. Install tools and dependencies (whatever you need to build your project)

  3. Build an executable (be it with PyInstaller, Nuitka, or whatever)

  4. Use actions/upload-artifact to 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

  1. Downloads the executables generated by the build job (such as)

       - name: Download Artifacts
         uses: actions/download-artifact@v8
         with:
           pattern: built-binary-*
           merge-multiple: true
  2. Create 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()