From e08cbf197fde11619405895ec1067d1b1caf88a1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 21 Nov 2023 14:57:21 -0500 Subject: [PATCH] Fix build on PyPy It appears that `Py_FileSystemDefaultEncodeErrors` is not part of the limited API, and PyPy does not have it. Since pybind11 does not have a wrapper for `PyUnicode_EncodeFSDefault` (the main reason I had switched to a `encode` call earlier), we need to call it ourselves manually. --- src/_tkagg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index 567d7f88ba22..3b58114a71c0 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -309,8 +309,8 @@ load_tkinter_funcs() module = py::module_::import("_tkinter"); // CPython } auto py_path = module.attr("__file__"); - py::bytes py_path_b = py_path.attr("encode")( - Py_FileSystemDefaultEncoding, Py_FileSystemDefaultEncodeErrors); + auto py_path_b = py::reinterpret_steal( + PyUnicode_EncodeFSDefault(py_path.ptr())); std::string path = py_path_b; auto tkinter_lib = dlopen(path.c_str(), RTLD_LAZY); if (!tkinter_lib) {