ofek / pyapp

Runtime installer for Python applications
https://ofek.dev/pyapp/
1.1k stars 24 forks source link

Tcl error using Tk #133

Open jplumail opened 1 month ago

jplumail commented 1 month ago

I got an error when trying to distribute my Tkinter app:

_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    /home/plumail/.local/share/pyapp/spfluo-app/7904589091198436804/0.1.12/bin/../lib/tcl8.6 /tools/deps/lib/tcl8.6 /home/plumail/.local/share/pyapp/spfluo-app/7904589091198436804/0.1.12/lib/tcl8.6 /home/plumail/.local/share/pyapp/spfluo-app/7904589091198436804/lib/tcl8.6 /home/plumail/.local/share/pyapp/spfluo-app/7904589091198436804/0.1.12/library /home/plumail/.local/share/pyapp/spfluo-app/7904589091198436804/library /home/plumail/.local/share/pyapp/spfluo-app/7904589091198436804/tcl8.6.12/library /home/plumail/.local/share/pyapp/spfluo-app/tcl8.6.12/library

This probably means that Tcl wasn't installed properly.

Apparently it is a known issue when distributing python: https://gregoryszorc.com/docs/python-build-standalone/main/quirks.html#tcl-tk-support-files

ofek commented 1 month ago

Thanks! If you can tell me your workaround then I can document as a troubleshooting note.

jplumail commented 1 month ago

This is the workaround in the link:

import os
import sys

os.environ["TCL_LIBRARY"] = os.path.join(os.path.dirname(sys.executable), "..", "lib", "tcl8.6")

import turtle

It doesn't work because tcl is not included in the lib folder. However I found it in the python distribution cached at ~/.cache/pyapp/distributions/_14656550572188801628/python/lib/tcl8.6/.

But when I try this path, I get a new error:

[xcb] Unknown sequence number while appending request [xcb] You called XInitThreads, this is not your fault [xcb] Aborting, sorry about that. python3: ../../src/xcb_io.c:157: append_pending_request: Assertion `!xcb_xlib_unknown_seq_number' failed. Abandon (core dumped)

To reproduce

curl https://github.com/ofek/pyapp/releases/latest/download/source.tar.gz -Lo pyapp-source.tar.gz
tar -xzf pyapp-source.tar.gz
mv pyapp-v* pyapp-latest
cd pyapp-latest

PYAPP_PROJECT_NAME=guitk PYAPP_PROJECT_VERSION=0.4.3 PYAPP_EXEC_MODULE=guitk cargo build --release

mv target/release/pyapp ../guitk && cd .. && chmod +x guitk

Then: TCL_LIBRARY=~/.cache/pyapp/distributions/YOUR_NUMBER/python/lib/tcl8.6/ ./guitk

jplumail commented 1 month ago

After searching a bit, I found this https://github.com/indygreg/python-build-standalone/issues/146 No update since November 2022...