Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4cc9cc

Browse files
committed
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 <module '_tkinter' (built-in)> 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 matplotlib#7428
1 parent 3e89069 commit b4cc9cc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/_tkagg.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,19 @@ int load_tkinter_funcs(void)
410410
// Load tkinter global funcs from tkinter compiled module.
411411
// Return 0 for success, non-zero for failure.
412412
int ret = -1;
413-
void *tkinter_lib;
413+
void *main_program, *tkinter_lib;
414414
char *tkinter_libname;
415415
PyObject *pModule = NULL, *pSubmodule = NULL, *pString = NULL;
416416

417+
// Try loading from the main program namespace first
418+
main_program = dlopen(NULL, RTLD_LAZY);
419+
if (_func_loader(main_program) == 0) {
420+
return 0;
421+
}
422+
// Clear exception triggered when we didn't find symbols above.
423+
PyErr_Clear();
424+
425+
// Now try finding the tkinter compiled module
417426
pModule = PyImport_ImportModule(TKINTER_PKG);
418427
if (pModule == NULL) {
419428
goto exit;

0 commit comments

Comments
 (0)