Ubuntu – Ubuntu 16.04: can’t open the terminal after trying to install Python


Yesterday I installed Ubuntu, but now I cannot open Terminal… I click on the Terminal icon and it doesn't start, and ctrl+alt+t isn't working either.

I've read different ways to fix this (and none of them worked)
One way was to open XTerm and type gnome-terminal. When I did that I got this output:

Could not find platform independent libraries < prefix >
Could not find platform dependent libraries < exec_prefix >
Consider setting $PYTHONHOME to < prefix >[:< exec_prefix >]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007f54f2451700 (most recent call first):
Aborted (core dumped)

Today I tried to install Python and it didn't work for some reason… maybe that caused some problem?

Another way that I read was to change the language and locale (I'm from Argentina)… but I have just found that Language Support doesn't open either!!

Best Answer

I had the same terminal problem after upgrading Python from 3.5 to 3.7. As noted, Python 3.5(m) comes preloaded in Ubuntu 16.04 and the executable is in /usr/bin whereas Python 3.7 is installed in /usr/local/lib. My XTerm showed:

dell:/usr/bin$ gnome-terminal 
bash: /usr/bin/gnome-terminal: /usr/bin/python3: bad interpreter: No such file or directory

Once I changed the first line of "gnome-terminal" from #!/usr/bin/python3 to #!/usr/bin/python3.5m, it was working. On the other hand, if I changed it to #!/usr/local/bin/python3.7, it encountered the following error:

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

This shows that ubuntu 16.04 gnomi-terminal is supported by Python 3.5, but not 3.7.

In your case, your error was "ImportError: No module named 'encodings'". I suppose your Python is 3.5 or earlier. I searched the Ubuntu16.04 gnome-terminal script, there is no such statement as "import encodings". As suggested, you might want to reinstall gnome-terminal. I am not familiar with Anaconda, but looks like the default installation of Anaconda2 includes Python 2.7 and Anaconda3 includes Python 3.7. For Python 3.5, you need to follow this instruction. So make sure your gnome-terminal Python script is supported by the installed Python version, to be sure, issue shell command "/usr/bin/python3 --version" or python3 -c "import sys; print('\n'.join(sys.path))"

Related Question