0

I'm trying to get matplotlib to work with WSL2 (Windows Subsystem for Linux 2). I've followed all the instructions from this post: https://stackoverflow.com/a/43399827/12851544 but unfortunately it's not working. I need to use python2.7 since I want to use the following C++ library: https://github.com/lava/matplotlib-cpp

The connection to the X-Server (VcXsrv) is working perfectly since I'm able to start xcalc from WSL2. But as soon as I run a simple python code to test matplotlib I get the following error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "/home/marcel/.local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/marcel/.local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 63, in pylab_setup
    [backend_name], 0)
  File "/home/marcel/.local/lib/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 12, in <module>
    from matplotlib.backends.backend_gtk import (
  File "/home/marcel/.local/lib/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 21, in <module>
    raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.

I've tried to install pygtk with pip but then I get the following error:

Collecting pygtk
  Downloading https://files.pythonhosted.org/packages/7c/18/fa4f2de77500dd62a314fd845ff6e903ac2ce551164cb421c5750969f799/pygtk-2.24.0.tar.bz2 (2.4MB)
    100% |████████████████████████████████| 2.4MB 737kB/s 
    Complete output from command python setup.py egg_info:
    ********************************************************************
    * Building PyGTK using distutils is only supported on windows. *
    * To build PyGTK in a supported way, read the INSTALL file.    *
    ********************************************************************
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-GMX7ld/pygtk/

python-tk is already installed (version 2.7.17-1~18.04).

I've also tested it with python3.6 but I get the same error.

Hope someone can help me.

shyney
  • 67
  • 11

1 Answers1

0

Ok I managed to solve it by myself. But if anyone gets to the same problem here is the solution:

Go to your matplotlibrc file usually located in ~.config\matplotlib\matplotlibrc and change the following row: backend : GTKAgg into backend : TkAgg

This solved it for me.

shyney
  • 67
  • 11