diff options
author | rnhmjoj <rnhmjoj@inventati.org> | 2021-05-26 01:24:27 +0200 |
---|---|---|
committer | rnhmjoj <rnhmjoj@inventati.org> | 2021-05-26 07:53:20 +0200 |
commit | 7e2ec8f8a15b77c14c185c4044e99ba05e8b6a38 (patch) | |
tree | 2ac3e722a7e7c432a9d62108e51e1556aeb5a256 /pkgs/development/python-modules/matplotlib | |
parent | 7e54c9b956db89eb698500d7a98f7890b6abc16f (diff) |
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"
Diffstat (limited to 'pkgs/development/python-modules/matplotlib')
-rw-r--r-- | pkgs/development/python-modules/matplotlib/default.nix | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/pkgs/development/python-modules/matplotlib/default.nix b/pkgs/development/python-modules/matplotlib/default.nix index 7364920cba22c..192ecf2fae018 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. |