python-build-standalone: Not able to run a tkinter program
I am using the bazel/rules_python to compile our python code. according to the configuration, we are using the cpython-3.9.13+20220802-x86_64-unknown-linux-gnu-install_only.tar.gz as our python interpreter. But as we are using the Tkinter, there is a segment fault during the runtime. the code
import faulthandler
faulthandler.enable()
import tkinter
from tkinter.constants import *
tk = tkinter.Tk()
frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
frame.pack(fill=BOTH,expand=1)
label = tkinter.Label(frame, text="Hello, World")
label.pack(fill=X, expand=1)
button = tkinter.Button(frame,text="Exit",command=tk.destroy)
button.pack(side=BOTTOM)
tk.mainloop()
the stack trace
/tmp/python_interpreter_x86_64-unknown-linux-gnu ❯ ./bin/python3.9 tkinter_test.py
Fatal Python error: Segmentation fault
Current thread 0x00007fe29108ef40 (most recent call first):
File "/tmp/python_interpreter_x86_64-unknown-linux-gnu/lib/python3.9/tkinter/__init__.py", line 2572 in __init__
File "/tmp/python_interpreter_x86_64-unknown-linux-gnu/lib/python3.9/tkinter/__init__.py", line 3148 in __init__
File "/tmp/python_interpreter_x86_64-unknown-linux-gnu/tkinter_test.py", line 9 in <module>
[1] 55139 segmentation fault (core dumped) ./bin/python3.9 tkinter_test.py
according to other tickets, seems the python interpreter is already linked to the Tkinter.
Update
I was trying to use the debug version to know what happened in the core dump. but it is very strange that I am able to run this with python3.9d. it is very weird.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 33 (5 by maintainers)
Let’s keep conversation here focused on the specific bug here rather than uv Python installation behaviors / pyenv / etc. please.
@alexis-massa
Remove the virtual environment and install python with some other tool like pyenv. Then use
Future runs will use the version from the newly created venv I’m pretty sure.
No, I don’t think that commit has been merged. It’s on an open branch.
Someone commented that this was not a problem on MS-Windows. I wanted to say I get the what seems to be the problem on MS-Windows.
But if I specify the python version installed from https://www.python.org/downloads/
The application is a basic TKinter app. https://github.com/rnwolf/my_tkinter_app
I fixed this with ff0ee27d1b2fb55d134efb19c0c0440fcf54e14f but am not happy with the approach
cc @geofft perhaps you have an idea of how to make that better? I think, at the very least, we should generate the contents replacing the
ALLexclusion.After a git bisect testing against OP code, I found that this commit is the first bad commit. I have no idea about how to fix this though !
I was able to repro this as well with
python-build-standaloneon3.10 - 3.13.Repro
main.pyWith a managed python:
Behavior - crash:
With a system python installed via
brew install python@3.13Expected behavior (no crash)
@linde12 i manage my dependencies with uv but my python installations with chocolatey on windows and on linux with pyenv. First i install pyenv set the string for the fish shell in the config and then i do the rest with uv and it works. I had this tkinter problem only on the Linux Systems
@rezzubs Ah!
Aha,
uv run -p 3.13 --python-preference only-managed test.pydoes not work either, but with-p 3.8it worked.No tcl error (which i’ve gotten before and worked around using
TCL_LIBRARYenv var) but reinstalling python 3.8 viauv python uninstall 3.8and then just runninguv run -p 3.8 --python-preference only-managed test.pyagain broke it.Perhaps i had a version of py 3.8 that was working, but after uninstalling and letting uv grab the latest 3.8 release it breaks. So basically only my system python & older (?) releases of python-build-standalone are working? 😦
EDIT: I saw that
cpython-3.8.20-linux-x86_64-gnudoes not work, however 3.8.2 - 3.8.12 are working!EDIT 2: Can confirm that
3.10.2& (released in 20220227) works, but so does3.10.3(released in 20220318) which was released in the same release as3.8.13which does not work!So two versions from the same release are inconsistent, 3.10.2 works whereas 3.8.13 from same release does not. I am very confused!
Also encountering this, using Arch (btw), but it is working with python 3.8 and 3.13 (none of which i can use in my project)
test.py:uv run -p 3.8 test.py- OKuv run -p 3.9 test.py- Failuv run -p 3.10 test.py- Failuv run -p 3.11 test.py- Failuv run -p 3.12 test.py- Failuv run -p 3.13 test.py- OKJust confirming this is still reproducible after upgrading tcl/tk (#495)
Thanks for the report.
Can confirm this fails on the latest 20221107 distributions. The x86_64-unknown-linux-gnu distribution fails for me on the
>>> label = tkinter.Label(frame, text="Hello, World")line:This program works with other Python builds on my system. So something is amiss.
The
xcbwarnings point to a potential interaction with that library. I reckon we’re missing a configure flag somewhere in the X11 libraries which results in something using a non-standard config. tk and/or CPython is probably making assumptions about some X library config that aren’t true.There’s possibly an upstream bug or two to report in here somewhere. But I don’t know what until root cause is understood.