pythonpython-3.xubuntu

ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import)


Looks like I have broken my python installation when I wanted to switch to python 3.8. Using Ubuntu 18.04. Trying to use the gi, gives the following error:

$ python
Python 3.8.1 (default, Dec 31 2019, 18:42:42) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> from gi.repository import GLib, Gio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gi/__init__.py)

Tried running update-alternatives for python, but it tells me there is only one python alternative configured (3.8).

Tried to reinstall python3-gi and python3.8. Still the same problem


Solution

  • I had the same issue. I linked python3 to python3.6, for me it was pointing to 3.8. That solved the issue.

    cd /usr/bin/
    rm python3
    ln -s python3.6 python3
    

    Thats all. Now my system started working fine.