Hello community,
I am trying to set up my Python scientific environment in NixOS 21.11, and I have stumbled against some issues with the matplotlib library. More specifically, I get the following error when trying to use the Gtk backend:
$ python -c 'import matplotlib.pyplot as plt; plt.plot()'
Traceback (most recent call last):
File "/nix/store/mar5qp8knkprymbany0h1ildlz5lf7i3-python3-3.9.6-env/lib/python3.9/site-packages/matplotlib/backends/backend_gtk3.py", line 24, in <module>
gi.require_version("Gtk", "3.0")
File "/nix/store/mar5qp8knkprymbany0h1ildlz5lf7i3-python3-3.9.6-env/lib/python3.9/site-packages/gi/__init__.py", line 126, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/nix/store/mar5qp8knkprymbany0h1ildlz5lf7i3-python3-3.9.6-env/lib/python3.9/site-packages/matplotlib/pyplot.py", line 2500, in <module>
switch_backend(rcParams["backend"])
File "/nix/store/mar5qp8knkprymbany0h1ildlz5lf7i3-python3-3.9.6-env/lib/python3.9/site-packages/matplotlib/pyplot.py", line 277, in switch_backend
class backend_mod(matplotlib.backend_bases._Backend):
File "/nix/store/mar5qp8knkprymbany0h1ildlz5lf7i3-python3-3.9.6-env/lib/python3.9/site-packages/matplotlib/pyplot.py", line 278, in backend_mod
locals().update(vars(importlib.import_module(backend_name)))
File "/nix/store/19j43hyh37jqnn9l7rg6shk5barbn209-python3-3.9.6/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/nix/store/mar5qp8knkprymbany0h1ildlz5lf7i3-python3-3.9.6-env/lib/python3.9/site-packages/matplotlib/backends/backend_gtk3agg.py", line 8, in <module>
from . import backend_agg, backend_gtk3
File "/nix/store/mar5qp8knkprymbany0h1ildlz5lf7i3-python3-3.9.6-env/lib/python3.9/site-packages/matplotlib/backends/backend_gtk3.py", line 28, in <module>
raise ImportError from e
ImportError
This is my current python config in environment.systemPackages
:
(let
my-python-packages = python-packages: with python-packages; [
# Scientific libraries
pandas
numpy
scipy
matplotlib
jupyter
ipython
# Gtk hell
pygobject3
pycairo
];
python-with-my-packages = python3.withPackages my-python-packages;
in
python-with-my-packages)
I have also in installed the packages gtk3
, cairo
, and gobject-introspection
, but I still get the same error. Any hint on how to solve this issue? Thanks in advance.