0

I'm running Ubuntu 18.04.4 LTS and encountered an issue where after updating my Python from 3.6 to 3.7.5 my terminal keyboard shortcut stopped working and clicking on the terminal icon wouldn't get it to run.

I found a solution on StackExchange but I have no idea why it worked and I would love to understand why. You can find the link below and the solution was

This way the upgrade to 3.7 is useless. You should edit the gnome-terminal file:

Open a terminal and issue the following commands:

cd /usr/bin
sudo nano gnome-terminal
Change #!/usr/bin/python3 to #!/usr/bin/python3.6.

This way you can still use the power of 3.7 and solve the issue with the terminal.

Could anyone try to explain what happened when I did this and why it worked? Would love to know for when I need to upgrade it again! Thank you!

Source: Terminal not opening up after upgrading python to 3.7

  • To add to what danzel has said, better still use a virtual environment! – George Udosen May 08 '20 at 07:37
  • @GeorgeUdosen Thanks Geroge, could you give a brief explanation of how a virtual environment would be implemented for something like this? Thanks for your tip! – Hitokiriz May 11 '20 at 02:06

2 Answers2

1

If you followed the upgrade path from the linked question, all you did is make the symlink /usr/bin/python3 point to python 3.7 instead of python 3.6.

The line you changed is called a "shebang" line. It tells the kernel which application to use to interpret the file.

Applications from Ubuntu repositories expect /usr/bin/python3 to be python 3.6 and may be incompatible with python 3.7.

So apparently, gnome-terminal is incompatible with 3.7 and if you change the shebang to explicitly point to 3.6 it works again.

You are not supposed to change the default python version, which is evident in the fact that it is not installed in debian alternatives by default. I'd recommend changing it back to 3.6 because there are probably a lot of other applications that won't work.

Instead of changing /usr/bin/python3, use /usr/bin/python3.7 on the command line or in shebang lines of your own python modules.

danzel
  • 6,044
  • Thanks so much for the reply and introduction of shebang lines! Is it possible to just change the path for the python3 command while leaving the shebang line intact?

    Most of what you said makes sense, but it's not quite clear to me why a different shebang line would cause the shortcuts to the terminal not work. Is the shebang line being executed upon starting the terminal?

    Thanks again, I appreciate your time!

    – Hitokiriz May 11 '20 at 02:04
  • I may have time to improve my answer tomorrow, but I'll try to answer your questions now: /usr/bin/gnome-terminal is a python script. To the kernel it is not different from any other text file. It's the shebang line (and the executable bit) that tells the kernel "If someone tries to invoke me like an executable binary, please use /usr/bin/python3 to interpret me". The actual application that will be invoked is python3 with the path to the script as parameter. When you press the terminal shortcut, it will ultimately result in an invocation of gnome-terminal. – danzel May 11 '20 at 17:42
  • Thanks for the explanation, that helps a lot! I totally didn't realize the script starting the gnome-terminal was in python. :D

    Is there any specific reason why this is a python script? The gnome-terminal itself is written in C right?

    – Hitokiriz May 19 '20 at 03:09
-1

I had upgraded to python 3.10.9 from python 3.8 using deadsnakes repo https://hackersandslackers.com/multiple-python-versions-ubuntu-20-04/

After a while Ubuntu system got restarted, I found out my terminal is messed up & could not open.

Then, I ran this command which basically regenerted locales. This will take a while to complete.

sudo locale-gen --purge

Then I tried opening gnome-terminal & I was able to open the terminal by using latest python version.

Hope this solution helps!