Standalone Python builds (python-build-standalone) keep Tcl/Tk next to
libpython on Linux. Only the python executable finds them, through its
RPATH, so tkinter failed to load in any simulator embedding the
interpreter. The libraries have no SONAME, so loading them from Python
first does not help. The package setup now adds that directory to
LD_LIBRARY_PATH of the VUnit process, like add_python_dll_to_path does
for PATH on Windows, and every simulator process inherits it.
The embedded_python example pointed TCL_LIBRARY and TK_LIBRARY at a
tcl8.6/tk8.6 directory under sys.prefix whether it existed or not. In a
virtual environment sys.prefix is not the Python installation, and a
Python with Tcl 9 has no tcl8.6 directory, so Tcl stopped finding its
own libraries. unset_tcl_installation did not restore anything. The
logic moves to tcl_installation.py: it uses sys.base_prefix, accepts
any Tcl version, only sets a variable to a directory that has the Tcl
or Tk scripts, and restores the previous values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
With a standalone Python build (python-build-standalone) on Linux, every test using tkinter (the PySimpleGUI dialogs, Matplotlib windows) fails inside the simulator, in two ways:
pythonexecutable ($ORIGIN/../lib). In a simulator the executable isnvc,ghdlorvsim, so_tkintercannot load them. They have no SONAME, so preloading them from Python withctypesdoes not help either (tried).set_tcl_installationintb_example.vhdalways setTCL_LIBRARY/TK_LIBRARYtotcl8.6/tk8.6undersys.prefix. In a virtual environmentsys.prefixis the environment rather than the Python installation, and a Python with Tcl 9 has notcl8.6. Without the override Tcl finds its libraries itself.unset_tcl_installation(old_environ = environ) kept a reference to the same object, so nothing was restored.Changes
native_library.add_python_libraries_to_library_path(), called from the packagesetup()for every simulator: on Linux, whensys.base_prefix/libhaslibtcl*.so, that directory is appended once toLD_LIBRARY_PATHof the VUnit process, which every simulator process inherits. The same approach asadd_python_dll_to_path()forPATHon Windows. Distribution Pythons, macOS and Windows are left alone.examples/embedded_python/tcl_installation.py: the Tcl/Tk setup of the example as a module (see the comment below for why), imported byset_tcl_installation.Tested
Linux, NVC 1.23-devel and GHDL 7.0.0-dev (mcode), a python-build-standalone CPython 3.14, no
LD_LIBRARY_PATHor other workaround:--without-attributes .expected_failure --without-attributes .optional_depstests/run.pypytest tests/test_python_bridge.pyTk with a display found its scripts (Tk 9.0.4) with the same lookup code. Not tested: Questa/ModelSim, Riviera-PRO, Active-HDL, macOS and Windows.
🤖 Generated with Claude Code