35

For some reason, I can't open the terminal through the shortcut (terminal icon) in Ubuntu 22.04. It works through Visual Studio Code, though, so that makes me confused. I tried using the F keys, but they are only working to the fn functions (such as controlling the brightness). I am not very knowledgeable on how Ubuntu works, so I am terribly confused.

I did try (unsuccesfully) to change my python version to 3.11.

Edit: The contents of /usr/share/applications/org.gnome.Terminal.desktop:

[Desktop Entry]
Name=Terminal
Comment=Use the command line
Keywords=shell;prompt;command;commandline;cmd;
TryExec=gnome-terminal
Exec=gnome-terminal
Icon=org.gnome.Terminal
Type=Application
Categories=GNOME;GTK;System;TerminalEmulator;
StartupNotify=true
StartupWMClass=Gnome-terminal
X-GNOME-SingleWindow=false
OnlyShowIn=GNOME;Unity;
Actions=new-window;preferences;
X-Ubuntu-Gettext-Domain=gnome-terminal

[Desktop Action new-window] Name=New Window Exec=gnome-terminal --window

[Desktop Action preferences] Name=Preferences Exec=gnome-terminal --preferences

7 Answers7

41

If you try to change your python version in Ubuntu, it will most certainly cripple your environment. Python is an integral part and may not be changed under any circumstances. There are many questions & answers about it in this forum.

What could you do?

Depending on how you installed it, try to remove every remnant of your python 3.11.x and install the original python from the repos.

Since you cannot open terminal, open a virtual terminal with ctrl + alt + f3 and login with your username and password.

If your "orignal" version was not removed, you may tell the system to use it again:

sudo update-alternatives --config python3

Select the Version 3.10.6, if provided.

If the alternatives group was removed, that will not work. Try this command:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --config python3

If all else fails you may need to reinstall Ubuntu.

What if you need another python version?

There are many possible ways to install any python version in a special environment like "pipenv", "anaconda", "venv", you name it. See here for a small overview of virtual environments.

The current python version in Ubuntu 22.04 is 3.10.6 as of today.

wjandrea
  • 14,543
kanehekili
  • 7,496
  • 1
  • 21
  • 38
  • 8
    I changed it back to python 3.10 and it worked! thanks! – user480840 Nov 30 '22 at 16:52
  • 5
    Fro me I have to use this command first sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 and then run sudo update-alternatives --config python3 – Jino Antony Jan 12 '24 at 08:01
  • 1
    @JinoAntony has the best solution in case the entire group was removed. – Tony Mar 24 '24 at 23:36
  • Why are you talking about update-alternatives? Different versions of python3 are not alternatives on Ubuntu (as you explained) and are not configured as such (at least as of 20.04). It should correctly say update-alternatives: error: no alternatives for python3 and you'll need to correct the symlink manually at /usr/bin/python3. – wjandrea Jun 25 '24 at 17:54
  • If you look at the history, someone else added this to my answer... But thanks for your edit. – kanehekili Jun 26 '24 at 20:46
13

Had a similar issue, a youtube video resolved my case, without using any cmd line. Go to settings -> Language&Settings -> Change English (United States) to English (Canada) then restart.

Inno
  • 131
3

An alternative to kanehekili's answer: my problem was that I redirected the python and python3 links in /bin to my newly-installed python3.11 (instead of the original python3.10).

So I had to:

  1. Go into virtual terminal mode (with CTRL + ALT + F3).
  2. cd /bin
  3. Verify the bad state with ln -s | grep python (see the bad python/python3 directions).
  4. Remove soft links with sudo rm ./python and sudo rm ./python3.
  5. Create new soft links with sudo ln -s python3.10 python3 and sudo ln -s python3 python.
  6. Close virtual terminal mode (with CTRL + ALT + F2).

After that everything worked.

A. Kali
  • 131
  • This and all the other answers are not really a fix. You change python then you reinstall there is no 100 percent way to fix this. – David DE Jun 24 '24 at 18:40
  • I'm not sure, in my case I just installed another python version on the machine, without removing the one that came out of the box (3.10.x still existed). The issue was that I replaced the soft links inside /bin, and (I think) this is where the terminal boot failed (expecting python to be python3.10 and not python3.11). – A. Kali Jun 26 '24 at 07:29
  • The result is the same you messed with the default python. – David DE Jun 26 '24 at 07:40
  • The problem was not because I installed another python version (this didn't affect anything), but that I manually changed files in /bin - reverting this fixed the issue. Didn't need to reinstall anything – A. Kali Jun 26 '24 at 08:13
  • I had to use Vscode terminal to remove the symbolic link as I couldn't go into virtual terminal mode. – AiA Apr 20 '25 at 14:56
0

For me it was Default Locales.

nano /etc/default/locales

Remove lines that have "LC" or just delete all lines. Reboot.

SamTzu
  • 91
0

I had to update my locale settings in ubuntu:

sudo update-locale LANG=de_DE.UTF-8 LC_MESSAGES=POSIX

Maybe you have to renew your locales or set it to your country.

Andy
  • 1
0

Because of VirtualBox's Auto mode, you can try this Youtube video explanation

This video also fixes other issues.

You can try changing language and region but after all => you should install manually instead of Auto mode of Virtual Box.

0

As a workaround, you may install Konsole, a terminal from KDE. It will work, but since the problem is in Python, a lot of stuff will not work. (And yes, I upgraded my python3 to 3.11.13)

$ 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 40, in <module>
    from . import _gi
ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gi/__init__.py)

So my recommendation is: if you really have to use Python 3.11, install both 3.10 and 3.11 for use with update-alternatives:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1

and a similar command for 3.10, which one should be 1 and which should be 2 is arguable; install Konsole to be used in the case of emergency; start your system with python 3.10 and only then switch it to 3.11 with

sudo update-alternatives --config python3

You will be able to open new terminal windows with Ctrl Shift N (but not via the launcher), while python3 --version will report "Python 3.11.13".