简体   繁体   English

ModuleNotFoundError:没有名为“gi”的模块

[英]ModuleNotFoundError: No module named 'gi'

I am trying to run the following program:我正在尝试运行以下程序:

import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst

Bu I am getting:但我得到:

Traceback (most recent call last):
  File "application.py", line 2, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

I am on a Mac Sierra (10.12.1 (16B2555)) using Python3.我在使用 Python3 的 Mac Sierra (10.12.1 (16B2555)) 上。

I've installed pygoject and gtk+3 (as can be seen here):我已经安装了 pygoject 和 gtk+3(可以在这里看到):

(cv) ✔ ~/Documents/test 
00:53 $ brew install pygobject3 --with-python3 gtk+3
Warning: pygobject3 3.24.1_1 is already installed
Warning: gtk+3 3.22.18 is already installed

My Python is from my virtualenv:我的 Python 来自我的 virtualenv:

(cv) ✘-1 ~/Documents/test 
00:53 $ which python
/Users/myuser/.virtualenvs/cv/bin/python

(cv) ✔ ~/Documents/test 
00:54 $ python --version
Python 3.6.1

If I try to uninstall gi to reinstall it (as I saw in some previous answers from Stack) I get:如果我尝试卸载 gi 以重新安装它(正如我在 Stack 之前的一些答案中看到的那样),我会得到:

(cv) ✘-1 ~/Documents/test 
00:55 $ pip uninstall gi
Cannot uninstall requirement gi, not installed

Any idea of what could solve my issue?知道什么可以解决我的问题吗?

In my case, as pointed by @NoufalIbrahim, the package was installed in the system directory, but not in the virtualenv.就我而言,正如@NoufalIbrahim 所指出的,该软件包安装在系统目录中,但未安装在 virtualenv 中。

I have solved the issue by executing:我已经通过执行解决了这个问题:

export PYTHONPATH=/usr/local/lib/python3.6/site-packages

You are getting this error due to missing gi library.由于缺少 gi 库,您收到此错误。 I solved this by running following command on OSX (Mac):我通过在 OSX (Mac) 上运行以下命令解决了这个问题:

brew install pygobject3 gtk+3

I solved it by installing the dependencies recommended in the install instructions of PyGObject:我通过安装 PyGObject 安装说明中推荐的依赖项解决了这个问题:

https://pygobject.readthedocs.io/en/latest/getting_started.html#getting-started https://pygobject.readthedocs.io/en/latest/getting_started.html#getting-started

Personally I solved running我个人解决了跑步

pip install vext
pip install vext.gi

尝试运行此命令:

sudo apt install python3-gi

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

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