From 7e2ec8f8a15b77c14c185c4044e99ba05e8b6a38 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Wed, 26 May 2021 01:24:27 +0200 Subject: [PATCH] pythonPackages.matplotlib: fix headless detection The default backend is chosen based on the content of the $DISPLAY variable *and* a successfull call to libX11, loaded via dlopen(). The test fails because dlopen looks in /usr/lib and /lib, so matplotlib falls back to a headless backend. To reproduce try running: $ nix-shell -I nixpkgs=$PWD -p \ 'python3.withPackages (p: [ p.matplotlib ])' --run python >>> import matplotlib.pyplot as plt >>> assert plt.get_backend() == "TkAgg" --- .../python-modules/matplotlib/default.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkgs/development/python-modules/matplotlib/default.nix b/pkgs/development/python-modules/matplotlib/default.nix index 7364920cba2..192ecf2fae0 100644 --- a/pkgs/development/python-modules/matplotlib/default.nix +++ b/pkgs/development/python-modules/matplotlib/default.nix @@ -5,12 +5,18 @@ , enableGhostscript ? true, ghostscript, gtk3 , enableGtk3 ? false, cairo # darwin has its own "MacOSX" backend -, enableTk ? !stdenv.isDarwin, tcl, tk, tkinter, libX11 +, enableTk ? !stdenv.isDarwin, tcl, tk, tkinter , enableQt ? false, pyqt5 +# required for headless detection +, libX11, wayland , Cocoa , pythonOlder }: +let + interactive = enableTk || enableGtk3 || enableQt; +in + buildPythonPackage rec { version = "3.4.1"; pname = "matplotlib"; @@ -62,8 +68,14 @@ buildPythonPackage rec { let tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"''; in - lib.optionalString enableTk - "sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py"; + lib.optionalString enableTk '' + sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py + '' + lib.optionalString (stdenv.isLinux && interactive) '' + # fix paths to libraries in dlopen calls (headless detection) + substituteInPlace src/_c_internal_utils.c \ + --replace libX11.so.6 ${libX11}/lib/libX11.so.6 \ + --replace libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0 + ''; # Matplotlib needs to be built against a specific version of freetype in # order for all of the tests to pass.