0

When I try to open the Terminal from Gauke Terminal or from XTerm by using

   gnome-terminal

it shows this error:

Traceback (most recent call last):
  File "/usr/bin/gnome-terminal", line 9, in <module>
    from gi.repository import GLib, Gio
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
from . import _gi
ImportError: cannot import name '_gi'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/usr/bin/gnome-terminal", line 9, in <module>
    from gi.repository import GLib, Gio
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
ImportError: cannot import name '_gi'

I cannot open terminal from launcher and dashboard, or by using Ctrl+Alt+T. I tried to reconfigure locale and ~/.profile but that didn't help.

1 Answers1

0

There are two important errors in the output, each is at the bottom of the two python error stacks:

  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
ImportError: cannot import name '_gi'
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Let's figure out which packages aren't working:

$ dpkg -S /usr/lib/python3/dist-packages/apt/__init__.py
python3-apt: /usr/lib/python3/dist-packages/apt/__init__.py

$ dpkg -S /usr/lib/python3/dist-packages/gi/__init__.py
python3-gi: /usr/lib/python3/dist-packages/gi/__init__.py

So the two packages for you to reinstall are python3-apt and python3-gi

However, those two packages are fundamental to the operation of your Ubuntu system, and it's really unlikely that both failed at once. Something else important is going on that you have not mentioned yet.

Chai T. Rex
  • 5,193
user535733
  • 62,253
  • Just a comment. My Windows 10 Ubuntu (WSL) got borked when I upgraded 16.04 to 18.04. Thousands of errors with Python 2 and Python 3 clashing with each other I think. I'll reinstall 16.04 fresh next time I need to boot Windows but it was sure annoying. – WinEunuuchs2Unix Jul 06 '18 at 02:20
  • Yeah, I think Microsoft probably needs to do some work to get 18.04 working right. – Chai T. Rex Jul 06 '18 at 03:36
  • @user535733 To format terminal output, paste it into your answer, select it with your mouse, and press the {} button in the editor. If you need spacing in between two code blocks that are right next to each other like above, insert <!-- --> between them. – Chai T. Rex Jul 10 '18 at 03:11
  • @ChaiT.Rex check that edit, looks like you overwrote one of the errors. Thanks for the tip! – user535733 Jul 10 '18 at 03:16
  • @user535733 Ahh, good catch. I had accidentally pasted the whole thing with both errors twice. – Chai T. Rex Jul 10 '18 at 03:22