13

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?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Gabrielle
  • 812
  • 2
  • 7
  • 28
  • 2
    My first guess is that you're using your virtualenv python but gi is installed in your system directory. Can you deactivate your virtualenv, try starting python and importing gi? If that works, we can figure something out. – Noufal Ibrahim Aug 14 '17 at 05:12
  • Try re-recreating the environment, as the bindings are installed against the system Python - so they may not be reflected in your (old) environment. Do a `pip freeze > requirements.txt` to capture what you have already installed, then recreate the environment again, and try. – Burhan Khalid Aug 14 '17 at 05:17
  • @NoufalIbrahim apparently this is the case because: 10:18 $ python Python 2.7.10 (default, Jul 30 2016, 18:31:42) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import gi >>> gi.require_version('Gst', '1.0') – Gabrielle Aug 14 '17 at 14:19
  • @NoufalIbrahim any ideas how to proceed? – Gabrielle Aug 14 '17 at 14:20
  • @NoufalIbrahim thanks :) – Gabrielle Aug 14 '17 at 14:59

5 Answers5

8

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
Gabrielle
  • 812
  • 2
  • 7
  • 28
  • 1
    My apologies. I couldn't follow up after my original comment. If this is indeed the problem, you should be able to do a `pip install gi` inside your virtualenv python and it should bring it in. The other thing you can do is to create your virtualenv with the `--system-site-packages` option so that it picks up packages in the path you've specified as well. No need to tinker with pythonpath manually. – Noufal Ibrahim Aug 16 '17 at 13:21
  • 1
    @NoufalIbrahim When I did what you suggested using pip, I got `ERROR: Could not find a version that satisfies the requirement gi (from versions: none) ERROR: No matching distribution found for gi`. Are you sure `gi` is the right name of the thingy to install? – kakyo Aug 10 '19 at 09:16
  • 1
    Are you on a mac? – Gabrielle Aug 11 '19 at 13:07
4

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)

Edoardo Vignati
  • 433
  • 5
  • 14
2

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
Community
  • 1
  • 1
Jagdish
  • 542
  • 4
  • 9
  • 2
    That's was not the case for me, if you look at my question, I show that I had run this command, I also show that whenever I tried to run the command again it would say that this library was already installed... the issue was an export site-packages missing.... – Gabrielle Jul 12 '19 at 17:42
1

I solved it by installing the dependencies recommended in the install instructions of PyGObject:

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

gitaarik
  • 42,736
  • 12
  • 98
  • 105
-8

Try running this command:

sudo apt install python3-gi
cs95
  • 379,657
  • 97
  • 704
  • 746
Kush Patel
  • 110
  • 2
  • I am on a Mac, and the equivalent command (brew install python3-gi) doesn't work... – Gabrielle Aug 14 '17 at 14:17
  • 3
    Even though this is the most downvoted answer, this SOLVED my side of the problem that even the most upvoted here can't solve. I'm probably just one of those edge-cases you always see in coding competitions, +1. – JumperBot_ Aug 24 '22 at 09:24