[英]ImportError: No module named gi.repository
I'm trying to launch python script on Ubuntu 10.04:我正在尝试在 Ubuntu 10.04 上启动 python 脚本:
from gi.repository import Nautilus, GObject
It doesn't work:它不起作用:
Traceback (most recent call last):
File "script.py", line 1, in <module>
from gi.repository import Nautilus, GObject
ImportError: No module named gi.repository
I installed python-gobject-dev
, python-gobject
, python-nautilus
, but it didn't help.我安装了
python-gobject-dev
、 python-gobject
、 python-nautilus
,但没有帮助。 Has anyone had this problem?有人遇到过这个问题吗?
sudo apt-get install -y python-gobject
在 Ubuntu 18.04 上为我修复了它。
conda install -c conda-forge pygobject
对 Anaconda 的回答对我不起作用,但conda install -c conda-forge pygobject
确实适用。
10.04? 10.04? That's pre-GNOME 3, so the preferred Python bindings were based on PyGTK, not PyGObject.
那是 GNOME 3 之前的版本,因此首选的 Python 绑定基于 PyGTK,而不是 PyGObject。 You need to either use the (obsolete) PyGTK bindings or upgrade to a newer OS.
您需要使用(过时的)PyGTK 绑定或升级到更新的操作系统。
You need to install pygobject, pygobject3(3 comes from the gtk version, not python).你需要安装pygobject,pygobject3(3来自gtk版本,不是python)。
If you're on Mac:如果您使用的是 Mac:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Install the latest version of homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
安装最新版本的homebrewbrew install pygobject
Install pyobject brew install pygobject
安装pyobjectbrew install pygobject3
Install pyobject3 brew install pygobject3
安装 pyobject3mkdir -p /Users/abhijit/Library/Python/2.7/lib/python/site-packages
Check and build the sitepath directory if it doesn't exist mkdir -p /Users/abhijit/Library/Python/2.7/lib/python/site-packages
检查并构建sitepath目录,如果它不存在echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/abhijit/Library/Python/2.7/lib/python/site-packages/homebrew.pth
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/abhijit/Library/Python/2.7/lib/python/site-packages/homebrew.pth
Create a shortcut in your python Site-packages to your homebrew path echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/abhijit/Library/Python/2.7/lib/python/site-packages/homebrew.pth
在你的 python 站点包到你的自制程序路径这对我有用(Ubuntu 20.04 LTS):
sudo apt reinstall python3-gi
very simple.很简单的。 open /usr/bin/gnome-terminal,you can see the interpreter is python3:
打开/usr/bin/gnome-terminal,可以看到解释器是python3:
#!/usr/bin/python3
Change the path of the interpreter to python3.5:将解释器的路径改为python3.5:
#!/usr/bin/python3.5
Fixed it for me on Ubuntu 16.04.在 Ubuntu 16.04 上为我修复了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.