简体   繁体   English

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

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

I am trying to run some code on an AWS ec2 (ubuntu).我正在尝试在 AWS ec2 (ubuntu) 上运行一些代码。 When I comment out the portion that displays graphs from matplotlib, it runs fine.当我从 matplotlib 中注释掉显示图形的部分时,它运行良好。 However, I want to view graphs.但是,我想查看图表。

When running the code, I get this error:运行代码时,我收到此错误:

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

I've been searching SO and other sources and have tried a lot of things including:我一直在搜索 SO 和其他来源,并尝试了很多东西,包括:

sudo apt-get install python3-gi

pip install vext
pip install vext.gi

sudo apt install python3-gi

pip3 install --user pgi

Also, this works:此外,这有效:

$ /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
>>> 

but my actual code is in a virtual env with a bunch of dependencies, so this doesn't work with my actual code ( /usr/bin/python run.py ).但是我的实际代码位于具有一堆依赖项的虚拟环境中,因此这不适用于我的实际代码( /usr/bin/python run.py )。

I ran into exact same issue, but after much efforts I managed to make TkAgg working (which was giving the import error for _tkagg).我遇到了完全相同的问题,但经过很多努力,我设法使 TkAgg 正常工作(这导致了 _tkagg 的导入错误)。 Little late, but someone might find it useful.有点晚了,但有人可能会发现它很有用。

FWIW I resolved the issue as follows (to use TkAgg): FWIW我解决了如下问题(使用TkAgg):

◉ Installed tk-dev from package manager ◉ 从包管理器安装 tk-dev

◉ Reinstalled python3-tk from package manager ◉ 从包管理器重新安装 python3-tk

◉ Rebuilt and reinstalled matplotlib from source ◉ 从源代码重建并重新安装 matplotlib

◉ (and of course setting TkAgg in matplotrc) ◉(当然还有在 matplotrc 中设置 TkAgg)

If you think you have tk-dev and python3-tk installed correctly, you need to rebuild and reinstall matplotlib, so that it generates _tkagg.py in your backends directory.如果你认为你已经正确安装了 tk-dev 和 python3-tk,你需要重建并重新安装 matplotlib,以便它在你的后端目录中生成 _tkagg.py。

I'm using Python3.3 (numpy 1.7) on LM14.我在 LM14 上使用 Python3.3(numpy 1.7)。 But I think it should work on Ubuntu/Python3.2但我认为它应该适用于 Ubuntu/Python3.2

Thanks谢谢

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

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