我按照安装指南进行操作: https://pygobject.readthedocs.io/en/latest/getting_started.html
然后我用“2.1.简单示例”测试了教程 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html#simple-example
但
python3 ./my.py失败如下:
File "./my.py", line 1, in <module>
import gi
ModuleNotFoundError: No module named 'gi'
Run Code Online (Sandbox Code Playgroud)
那么我该怎么做才能使导入成功呢?
说明:Ubuntu 16.04.6 LTS
您需要为 python3 安装 gi 模块,如下所示:
sudo apt install python3-gi
Run Code Online (Sandbox Code Playgroud)
您还可以通过 pip3 安装它(如果已经安装了 pip3),但请注意模块名称不同:
pip3 install --user pgi
Run Code Online (Sandbox Code Playgroud)
您需要将所有引用从gi更改为pgi。