israel-dryer / ttkbootstrap

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.
MIT License
1.79k stars 363 forks source link

Bundling into appimage result in `_tkinter.TclError: invalid command name "::msgcat::mcmset"` #470

Open laggykiller opened 1 year ago

laggykiller commented 1 year ago

Desktop (please complete the following information):

ttkbootstrap v1.10.1 OS: Ubuntu 20.04

Describe the bug

I tried to bundle a python application with ttkbootstrap into appimage. I am using appimage-bundler (https://github.com/AppImageCrafters/appimage-builder).

If a simple python script with ttkbootstrap packed into appimage, _tkinter.TclError: invalid command name "::msgcat::mcmset" would occur when the appimage is executed.

The issue seems to be related to https://github.com/Nuitka/Nuitka/issues/1440 and https://github.com/israel-dryer/ttkbootstrap/issues/184 ? I have read those and still not quite sure what had happened.

To Reproduce

First download appimage-bundler from https://github.com/AppImageCrafters/appimage-builder

I was using https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage

chmod +x appimage-builder-1.1.0-x86_64.AppImage

Create the following files:

main.py

import ttkbootstrap as ttk
root = ttk.Window(themename='darkly')
root.mainloop()

AppImageBuilder.yml

# appimage-builder recipe see https://appimage-builder.readthedocs.io for details
# Works on ubuntu20
version: 1
script:
  # Remove any previous build
  - rm -rf AppDir  | true
  # Make usr dirs
  - mkdir -p AppDir/usr/src
  # Copy the python application code into the AppDir
  - cp ./main.py AppDir/usr/src
  # Install application dependencies
  - python3 -m pip install --system --ignore-installed --prefix=/usr --root=AppDir ttkbootstrap

AppDir:
  path: ./AppDir

  app_info:
    id: com.laggykiller.appimage_test
    name: appimage-test
    version: latest
    exec: usr/bin/python3
    exec_args: "$APPDIR/usr/src/main.py $@"

  apt:
    arch: amd64
    allow_unauthenticated: true
    sources:
    - sourceline: deb https://ppa.launchpadcontent.net/zero-tsuki/ppa/ubuntu focal main
    - sourceline: deb http://archive.ubuntu.com/ubuntu/ focal main restricted
    - sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
    - sourceline: deb http://archive.ubuntu.com/ubuntu/ focal universe
    - sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
    - sourceline: deb http://archive.ubuntu.com/ubuntu/ focal multiverse
    - sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
    - sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
    - sourceline: deb http://security.ubuntu.com/ubuntu focal-security main restricted
    - sourceline: deb http://security.ubuntu.com/ubuntu focal-security universe
    - sourceline: deb http://security.ubuntu.com/ubuntu focal-security multiverse

    include:
      - python3
      - python3-tk
    exclude: []

  # after_bundle: |
  #   cp -r AppDir/usr/share/tcltk/tcl8.6/tcl8/*.tm AppDir/usr/src

  runtime:
    env:
      # Set python home
      # See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHOME
      PYTHONHOME: '${APPDIR}/usr'
      # Path to the site-packages dir or other modules dirs
      # See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH
      PYTHONPATH: '${APPDIR}/usr/lib/python3.8/site-packages'
      # SSL Certificates are placed in a different location for every system therefore we ship our own copy
      # SSL_CERT_FILE: '${APPDIR}/usr/lib/python3.8/site-packages/certifi/cacert.pem'
      # Tcl library has to be specified or else cannot find init.tcl
      TCL_LIBRARY: '${APPDIR}/usr/share/tcltk/tcl8.2'

  files:
    include: []
    exclude:
    - usr/share/man
    - usr/share/doc/*/README.*
    - usr/share/doc/*/changelog.*
    - usr/share/doc/*/NEWS.*
    - usr/share/doc/*/TODO.*

AppImage:
  arch: x86_64
  update-information: guess

Finally run ./appimage-builder-1.1.0-x86_64.AppImage

The resulting appimage is appimage-test-latest-x86_64.AppImage

Running the appimage would cause the following error:

Traceback (most recent call last):
  File "/tmp/.mount_appima9ASyip/usr/src/main.py", line 3, in <module>
    root = ttk.Window(themename='darkly')
  File "/tmp/.mount_appima9ASyip/usr/lib/python3.8/site-packages/ttkbootstrap/window.py", line 279, in __init__
    self._style = Style(themename)
  File "/tmp/.mount_appima9ASyip/usr/lib/python3.8/site-packages/ttkbootstrap/style.py", line 489, in __init__
    localization.initialize_localities()
  File "/tmp/.mount_appima9ASyip/usr/lib/python3.8/site-packages/ttkbootstrap/localization/msgs.py", line 9, in initialize_localities
    m.initialize()
  File "/tmp/.mount_appima9ASyip/usr/lib/python3.8/site-packages/ttkbootstrap/localization/msgs.py", line 27, in initialize
    MessageCatalog.set_many(self.locale, *messages)
  File "/tmp/.mount_appima9ASyip/usr/lib/python3.8/site-packages/ttkbootstrap/localization/msgcat.py", line 142, in set_many
    return int(root.tk.eval(out))
_tkinter.TclError: invalid command name "::msgcat::mcmset"

Note that TCL_LIBRARY: '${APPDIR}/usr/share/tcltk/tcl8.2' in AppImageBuilder.yml is necessary, or else error occurs even more early on with:

Traceback (most recent call last):
  File "/tmp/.mount_appimakIqwGf/usr/src/main.py", line 3, in <module>
    root = ttk.Window(themename='darkly')
  File "/tmp/.mount_appimakIqwGf/usr/lib/python3.8/site-packages/ttkbootstrap/window.py", line 222, in __init__
    super().__init__()
  File "/tmp/.mount_appimakIqwGf/usr/lib/python3.8/site-packages/ttkbootstrap/style.py", line 5169, in __init__wrapper
    func(self, *args, **kwargs)
  File "/tmp/.mount_appimakIqwGf/usr/lib/python3.8/tkinter/__init__.py", line 2270, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    /tmp/.mount_appimakIqwGf/usr/share/tcltk /tmp/.mount_appimakIqwGf/usr/share/tcl8.6 /usr/share/tcltk/tcl8.6 /tmp/.mount_appimakIqwGf/usr/lib/tcl8.6 /tmp/.mount_appimakIqwGf/lib/tcl8.6 /tmp/.mount_appimakIqwGf/usr/library /tmp/.mount_appimakIqwGf/library /tmp/.mount_appimakIqwGf/tcl8.6.10/library /tmp/tcl8.6.10/library

This probably means that Tcl wasn't installed properly.

Note that following adivce from https://github.com/israel-dryer/ttkbootstrap/issues/184 and adding cp -r AppDir/usr/share/tcltk/tcl8.6/tcl8/*.tm AppDir/usr/src to AppImageBuilder.yml does NOT resolve the issue.

You may download the appimage-test-latest-x86_64.AppImage: https://drive.google.com/file/d/1a58ItQ6WWRmfjo46cIFbJF6ofQqa9OGL/view?usp=sharing

Expected behavior

No response

Screenshots

No response

Additional context

No response

laggykiller commented 1 year ago

Using 1.5.1 solved the problem, as suggested in https://github.com/israel-dryer/ttkbootstrap/issues/184