Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I've installed pygoject and gtk+3 (as can be seen here):

(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:

(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:

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

Any idea of what could solve my issue?

like image 798
Gabrielle Avatar asked Aug 14 '17 05:08

Gabrielle


People also ask

What is GI module in Python?

The require_version method ensures the namespace gets loaded with the given version. The gi. repository is the Python module for PyGObject . PyGObject (Python GObject introspection) contains Python bindings and support for GObject, GLib, GTK and other libraries.

What is GI repository?

gi. repository is the Python module for PyGObject (which stands for Python GObject introspection) which holds Python bindings and support for the GTK+ 3 toolkit and for the GNOME apps. See Projects/PyGObject on the GNOME Wiki. It has nothing to do with GitHub.


Video Answer


3 Answers

In my case, as pointed by @NoufalIbrahim, the package was installed in the system directory, but not in the virtualenv.

I have solved the issue by executing:

export PYTHONPATH=/usr/local/lib/python3.6/site-packages
like image 144
Gabrielle Avatar answered Oct 12 '22 22:10

Gabrielle


You are getting this error due to missing gi library. I solved this by running following command on OSX (Mac):

brew install pygobject3 gtk+3
like image 20
Jagdish Avatar answered Oct 13 '22 00:10

Jagdish


Personally I solved running

pip install vext
pip install vext.gi

Another solution I found

pip install homekit
pip install pygobject

(Debian users: you can replace homekit with sudo apt install libgirepository1.0-dev)

like image 43
Edoardo Vignati Avatar answered Oct 12 '22 22:10

Edoardo Vignati