11

When I run gnome-terminal, I get the following error:

Traceback (most recent call last):
  File "/usr/bin/gnome-terminal", line 9, in <module>
    from gi.repository import GLib, Gio
  File "/usr/local/lib/python3.4/dist-packages/gi/__init__.py", line 39
    print url

This looks odd to me, because the script is located in a python 3.4 installation but is calling print as if it was a python2 script (which is why the error occurs).

I tried to reinstall the package gi with pip3, but it keeps installing this version that looks like a python2 script.

My gnome-terminal points to /usr/bin/gnome-terminal, which is a python script that starts with #!/usr/bin/python3.

The lines with that particular error in init.py are:

if __name__ == '__main__':                                                                                                                                                                                                                                                                                      
         try:                                                                                                                                                                                                                                                                                                    
                 url = save_file()                                                                                                                                                                                                                                                                               
                 print url                                                                                                                                                                                                                                                                                   
         except GistError as e:                                                                                                                                                                                                                                                                                  
                 print e.value     

This suggests a quick fix: putting parenthesis in those two print lines.

  File "/usr/bin/gnome-terminal", line 9, in <module>
    from gi.repository import GLib, Gio
ImportError: No module named 'gi.repository'

Which is strange.

This must be running on /usr/bin/python3, because that's what on the shebang on /usr/bin/gnome-terminal.

python3 on the /usr/bin is actually a link to python3.4, which is a binary file.

I then run pip3 install gi and I get the following output, which tells me that actually gi is installed.

Requirement already satisfied (use --upgrade to upgrade): gi in /usr/local/lib/python3.4/dist-packages
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/lib/python3/dist-packages (from gi)

And right now I am out of ideas.

This started after I tried to install a Pumubuntu from https://github.com/Pumubuntu/Pumubuntu.

In the main script file it says:

import sys
if len(sys.argv) == 1:
    print('Importing Python modules. If one is missing get it with:\n'
          '  "sudo apt-get install python-..." or\n'
          '  "sudo apt-get install girX.Y-..." for gi.repository imports.')

So I thought I had to enter those commands. And that must have broken my gir installation (gir).

Can anybody help me?

  • What version of Ubuntu are you running? – Robᵩ Sep 17 '15 at 21:59
  • 15.04, I tried sudo pip3 install pygobject but it fails with "raise SystemExit, 'ERROR: Nothing to do, gio could not be found and is essential.'" Trying sudo apt-get install --reinstall glib gets me back to "ImportError: No module named 'gi.repository'" again during the setup script. –  Sep 17 '15 at 22:02
  • 1
    I'm really not sure what Ubuntu messed up here; this wrapper script is provided by them. Mainstream gnome-terminal is a binary which is probably present for you as `/usr/bin/gnome-terminal.real` or similar, and does not use python at all. You can try to directly launch this one. – egmont Sep 21 '15 at 23:04

6 Answers6

16

Another way to fix this error that I found was to modify the gnome-terminal script located in /usr/bin/ and changing the environment (first line of the script) from #!/usr/bin/python3 to #!/usr/bin/python to switch from Python 3 to Python 2 as the Github command line is for Python 2 as noted in the previous answer.

Therefore, open up xterm by pushing the Super key (Key beside the bottom left Alt key) or by pushing Alt + F2 and typing in xterm to search for an alternative terminal and clicking on it to run. Next, type in sudo gedit /usr/bin/gnome-terminal, push ENTER and edit the first line in accordance to above. It's not the best solution as you shouldn't have to edit the script but it worked for me and it didn't require uninstalling anything.

Update

The most current build of this requires Python 3, so as Jon M. in his comments stated, change the first line of the file to use Python 3.5:

#!/usr/bin/python3.5
rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • 2
    @theawless's solution didn't help me, but modifying the gnome-terminal script did work for me. – Jon M Dec 13 '17 at 20:00
  • 1
    Hmmm... after yet another rebuild, it seems that changing the 1st line (this time) to #!/usr/bin/python3.5 worked (broke on installing Python 3.6) – Jon M Dec 17 '17 at 12:05
  • 1
    Switch #!/usr/bin/python3 to #!/usr/bin/python - This work! – Yanov Nov 03 '20 at 12:04
10

In Python 3.5, I do this:

  1. sudo vim /usr/bin/gnome-terminal
  2. Modify the first line from #!/usr/bin/python to #!/usr/bin/python3.5

This fixed my problem!

rayryeng
  • 102,964
  • 22
  • 184
  • 193
zhengtao
  • 101
  • 1
  • 3
  • 1
    After upgrading to Python 3.6, gnome-terminal wouldn't start. This change fixed it for me, thank you. – Jamie Oct 15 '18 at 16:59
7

This is an old question but this being the first google hit, it should be answered.

The error is caused by installing gi package on python3.
It is a package for GIST Github commandline for python2. It is not related to gnome object or gnome introspection. Visit it here: python gi on package (aka pygobject)

It causes naming conflicts with gi.repository, rather than looking for gir in your python dist-packages, your system __init__ the gi package. And hence the error shows

ImportError: No module named 'gi.repository'

Uninstalling that package will resolve the error. Also if you are looking for a gister, try defunkt gist

Noam Manos
  • 15,216
  • 3
  • 86
  • 85
theawless
  • 71
  • 2
  • 6
  • Uninstalling gi causes the missing paranthesis error to change to a no mudle named 'gi' error, but doesn't fix the problem. – poleguy Oct 14 '16 at 16:56
  • Maybe your gi installation is messed up. Try reinstalling it. – theawless Dec 01 '16 at 16:57
  • 1
    I believe gi (https://pypi.python.org/pypi/gi) is buggy, it installs 2.x code to all /usr/local/lib/python3.x/dist-packages folders; and the project seems abandoned, the home page is not available, and I could not find any place to submit an issue. – Felix Mar 28 '17 at 19:15
  • 1
    I had to resort to changing /usr/bin/gnome-terminal, as suggested by rayryeng, which fixed my issue. But I agree that it'd be cleaner to uninstall gi. What would be the command for doing this? (I tried both pip uninstall gi and pip3 uninstall gi but was told that the package exists in neither location) – Robert Townley Aug 08 '17 at 15:29
5

I was also getting this issue after update python3.5 to python3.6

This is not the better way but working fine.

this issue occurs due to _gi_cairo . I resolved it by following code

 cd /usr/lib/python3/dist-packages/gi/
 sudo cp _gi.cpython-35m-x86_64-linux-gnu.so _gi.cpython-36m-x86_64-linux-gnu.so
 sudo cp _gi_cairo.cpython-35m-x86_64-linux-gnu.so _gi_cairo.cpython-36m-x86_64-linux-gnu.so
Somil
  • 1,921
  • 1
  • 21
  • 35
0

Happened to me with /usr/bin/chrome-gnome-shell script, on Linux (RHEL 7.6):

Traceback (most recent call last):
Traceback (most recent call last):
  File "/usr/bin/chrome-gnome-shell", line 16, in <module>
    from gi.repository import GLib, Gio
ModuleNotFoundError: No module named 'gi'

To fix it I had to install PyGObject:

$ sudo yum install python36-gobject.x86_64
# or directly with pip: pip3 install PyGObject

Once completed installation, running the script showed no error.

Noam Manos
  • 15,216
  • 3
  • 86
  • 85
0

Changing Python 3 version causes more than gnome-terminal to fail to start, as Python 3 is essential for many components to run. When you install a newer version of Python, not all packages necessary for all components are installed for new Python; in the case of gnome-terminal it's gi, and in case of other applications there are others. So be very careful with upgrading Python 3.

Use update-alternative to choose the former Python version will work, as it will point python3 alternatives to the correct version with gi installed. If nothing to config, try install your 2 versions of python into update-alternatives and choose former version.

WesternGun
  • 11,303
  • 6
  • 88
  • 157