【问题标题】:Using matplotlib with python2.7, WSL2 and VcXsrv backend requires pygtk在 python2.7、WSL2 和 VcXsrv 后端使用 matplotlib 需要 pygtk
【发布时间】:2020-12-10 14:21:49
【问题描述】:

我正在尝试让 matplotlib 与 WSL2(Linux 2 的 Windows 子系统)一起使用。 我已按照这篇文章中的所有说明进行操作:https://stackoverflow.com/a/43399827/12851544 但不幸的是它不起作用。 我需要使用 python2.7,因为我想使用以下 C++ 库:https://github.com/lava/matplotlib-cpp

与 X-Server (VcXsrv) 的连接工作正常,因为我能够从 WSL2 启动 xcalc。但是,一旦我运行一个简单的 python 代码来测试 matplotlib,我就会收到以下错误:

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.

我尝试使用 pip 安装 pygtk,但出现以下错误:

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 已经安装(版本 2.7.17-1~18.04)。

我也用 python3.6 测试过,但我得到了同样的错误。

希望有人可以帮助我。

【问题讨论】:

    标签: python matplotlib windows-subsystem-for-linux


    【解决方案1】:

    好的,我自己设法解决了。但如果有人遇到同样的问题,这里就是解决方案:

    转到通常位于 ~.config\matplotlib\matplotlibrc 中的 matplotlibrc 文件并更改以下行: backend : GTKAgg 进入 backend : TkAgg

    这为我解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-20
      • 1970-01-01
      • 2023-03-03
      • 2021-01-29
      • 2020-11-11
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      相关资源
      最近更新 更多