From b4cc9cceb7a62f8bddb9a2e389046a60eabec6e9 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Wed, 9 Nov 2016 00:53:23 -0800 Subject: [PATCH] FIX: search for tkinter first in builtins Python compiled from Python.org source builds the tkinter module as a built-in module, not an external module, as is the case for the packaged builds of Debian etc: >>> Tkinter.tkinter This breaks the MPL algorithm for searching for tkinter symbols, which loaded the external module .so file to get the symbols. Try searching in the main program namespace for the tkinter symbols, before looking for the extermal module .so file. Thanks to github user ettaka for reporting : see https://github.com/matplotlib/matplotlib/issues/7428 --- src/_tkagg.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index e0b5f58ebbc..1316b4b882a 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -410,10 +410,19 @@ int load_tkinter_funcs(void) // Load tkinter global funcs from tkinter compiled module. // Return 0 for success, non-zero for failure. int ret = -1; - void *tkinter_lib; + void *main_program, *tkinter_lib; char *tkinter_libname; PyObject *pModule = NULL, *pSubmodule = NULL, *pString = NULL; + // Try loading from the main program namespace first + main_program = dlopen(NULL, RTLD_LAZY); + if (_func_loader(main_program) == 0) { + return 0; + } + // Clear exception triggered when we didn't find symbols above. + PyErr_Clear(); + + // Now try finding the tkinter compiled module pModule = PyImport_ImportModule(TKINTER_PKG); if (pModule == NULL) { goto exit;