ImportError:cannot import name '_gi' while trying to add any PPA repository

12,183

Sounds like your system might have issues choosing the correct Python version.

Try editing the file /usr/bin/add-apt-repository and changing out the line #!/usr/bin/python3 with the specific version of python, in your case:

#!/usr/bin/python3.8

Alternatively see if you have an older working version of python installed that you could use instead:

ls -al /usr/bin | grep python

look for other versions, like python3.5 or python3.6 and try replacing the #!/usr/bin/python3.8 with the apropriate version number.

Share:
12,183

Related videos on Youtube

Abdullah Ar Rayhan
Author by

Abdullah Ar Rayhan

Updated on September 18, 2022

Comments

  • Abdullah Ar Rayhan
    Abdullah Ar Rayhan almost 2 years

    I have been trying to install MPV on my Ubuntu (18.04 LTS). Whenever I am trying to add a PPA repository to my system I get this error.

    For example, I tried this:

    sudo add-apt-repository ppa:mc3man/mpv-tests
    

    And got this:

    Traceback (most recent call last):
      File "/usr/bin/add-apt-repository", line 11, in <module>
        from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
      File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 67, in <module>
        from gi.repository import Gio
      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)
    

    It happens every time I am trying to add any PPA to my system. I had Python 3.6 installed by default but later updated to Python 3.8.0. I am new to Linux. What might be causing this problem? And How to solve this?

    Thank you!