没有模块"gi"和导入错误:GTK3后端需要PyGObject错误



我正在尝试在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上使用Python 3.3(numpy 1.7(。但我认为它应该在Ubuntu/Python3.2上运行

感谢

最新更新