This question already has an answer here:

I installed Python3 yesterday, but I have the feeling I didn't do a good job:

:~$ gnome-terminal
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' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)

I get the same error when trying to remove the PPA (in 404) with:

 add-apt-repository --remove ppa:/jonathonf/python-3.7

And yet, Python runs smoothly. This might be helpful too:

~$ python --version
Python 2.7.15rc1
~$ python3 --version
Python 3.7.0b3
~$ type -a python3; file $(type -aP python3)
python3 is /usr/bin/python3
/usr/bin/python3: symbolic link to /etc/alternatives/python3
~$ python3.5 --version # Expected, I installed 3.6 and 3.7 - I only added the 3.5 link as a following desperate attempt
bash: /usr/lib/command-not-found: /usr/bin/python3: bad interpreter: No such file or directory
~$ python3.6 --version
Python 3.6.5
~$ python3.7 --version
Python 3.7.0b3

Running Ubuntu 18.04

The error persists after re-installing gnome-terminal. I've found this post that doesn't have an answer, but they suggest to re-install Ubuntu, like, I hope they're joking (:

marked as duplicate by wjandrea, karel, Thomas, waltinator, Eric Carvalho Aug 1 '18 at 18:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • How did you install Python 3.7? What version of Ubuntu are you running? – wjandrea Jul 31 '18 at 19:17
  • 1
    I'm the one that commented about reinstalling Ubuntu on the linked post. That was because OP corrupted their packaging system (not sure which part). I'm not sure if that's a direct result of the original issue or tangential. I've added a comment to that effect on that post. – wjandrea Jul 31 '18 at 19:19
  • Update: regardless of how you installed Python 3.7, you've done it wrong. The program called python3 must point to the version of Python 3 that came with Ubuntu (and that is Python 3.6 or lower for any current Ubuntu release). Run type -a python3; file $(type -aP python3) and that will give us more info about your current setup. – wjandrea Jul 31 '18 at 19:26
  • Thank you all for caring, question updated. I used a few resources to Install Python, mainly ubuntuhandbook.org/index.php/2017/07/install-python-3-6-1-in-ubuntu-16-04-lts , at some point, I had to deviate with ln -s apt_pkg.cpython-{35m,34m}-x86_64-linux-gnu.so; ln -s apt_pkg.cpython-{36m,37m}-x86_64-linux-gnu.so – ecoologic Jul 31 '18 at 22:04
  • Ubuntu 18.04 contains (and probably even installs by default) python 3.6 packages. Yet, for 18.04, you followed an article dated 2017/07 about how to install it for Ubuntu 16.04, an article that clearly predates your distro release. I know that my comment here is not helpful, sorry for that, but I sincerely hope that this experience here will help you in the future to take precaution which articles to blindly follow, and to look for more mainstream, more official approaches first. – egmont Aug 1 '18 at 12:41

Step 3 in the instructions you followed is wrong. Different versions of Python 3 are not alternatives. Thankfully, it should be easy to fix. Just use similar commands to the ones in the update at the bottom of the post:

sudo rm /usr/bin/python3
sudo ln -s python3.6 /usr/bin/python3
  • Thank you very much. The weird thing (for me) is that I really taught I did that step too. In fact, I could already type python3.6 and I got: Python 3.6.5. Is that possible or am I just missing too much sleep? – ecoologic Jul 31 '18 at 22:25
  • 1
    I'm not really sure what you mean. Python 3.6.5 is the version that's installed by default on 18.04, so of course python3.6 runs it. python3 needs to run Python 3.6.5. Glad I could help, btw! – wjandrea Jul 31 '18 at 22:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.