繁体   English   中英

没有模块 'gi' 和 ImportError:GTK3 后端需要 PyGObject 错误

[英]No module 'gi' and ImportError: The GTK3 backends require PyGObject error

我正在尝试在 AWS ec2 (ubuntu) 上运行一些代码。 当我从 matplotlib 中注释掉显示图形的部分时,它运行良好。 但是,我想查看图表。

运行代码时,我收到此错误:

Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 18, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "run.py", line 8, in <module>
    from process_mask import ProcessMasks
  File "/home/ubuntu/rPPG/process_mask.py", line 10, in <module>
    matplotlib.use('GTK3Agg')
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py", line 307, in wrapper
    return func(*args, **kwargs)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/__init__.py", line 1307, in use
    switch_backend(name)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 221, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3agg.py", line 4, in <module>
    from . import backend_agg, backend_cairo, backend_gtk3
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 20, in <module>
    raise ImportError("The GTK3 backends require PyGObject")
ImportError: The GTK3 backends require PyGObject

我一直在搜索 SO 和其他来源,并尝试了很多东西,包括:

sudo apt-get install python3-gi

pip install vext
pip install vext.gi

sudo apt install python3-gi

pip3 install --user pgi

此外,这有效:

$ /usr/bin/python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> 

但是我的实际代码位于具有一堆依赖项的虚拟环境中,因此这不适用于我的实际代码( /usr/bin/python run.py )。

我遇到了完全相同的问题,但经过很多努力,我设法使 TkAgg 正常工作(这导致了 _tkagg 的导入错误)。 有点晚了,但有人可能会发现它很有用。

FWIW我解决了如下问题(使用TkAgg):

◉ 从包管理器安装 tk-dev

◉ 从包管理器重新安装 python3-tk

◉ 从源代码重建并重新安装 matplotlib

◉(当然还有在 matplotrc 中设置 TkAgg)

如果你认为你已经正确安装了 tk-dev 和 python3-tk,你需要重建并重新安装 matplotlib,以便它在你的后端目录中生成 _tkagg.py。

我在 LM14 上使用 Python3.3(numpy 1.7)。 但我认为它应该适用于 Ubuntu/Python3.2

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM