'ModuleNotFoundError: No module named 'gi' , how we can fixed it

from threading import Thread
from time import sleep
import gi

gi.require_version("Gst", "1.0")

from gi.repository import Gst, GLib


Gst.init()

main_loop = GLib.MainLoop()
thread = Thread(target=main_loop.run)
thread.start()

pipeline = Gst.parse_launch("ksvideosrc ! decodebin ! videoconvert ! autovideosink")
pipeline.set_state(Gst.State.PLAYING)

try:
    while True:
        sleep(0.1)
except KeyboardInterrupt:
    pass

pipeline.set_state(Gst.State.NULL)
main_loop.quit()
main_loop_thread.join()

My output error

ModuleNotFoundError                       Traceback (most recent call last) <ipython-input-1-ab92d040e545> in <module>
      1 from threading import Thread
      2 from time import sleep
----> 3 import gi
      4 
      5 gi.require_version("Gst", "1.0") ModuleNotFoundError: No module named 'gi'

please tell me how I can fixed it.



Solution 1:[1]

not sure which OS you're on but if on linux ensure you have deps installed for building gtk ,

sudo apt install libcairo2-dev libxt-dev, libgirepository1.0-dev
pip3 install PyGObject, pycairo  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alejo Herny