Python Upgrading leads to terminal... not opening
Asked Answered
H

4

11

I just upgraded python in ubuntu to python 3.10 to use the match/case statements, but now, my terminal won't open. Anywhere. I tired opening it on Visual Studio Code, but it says the path does not exist. Gnome terminal and terminator won't even give any feedback. I am using Ubuntu 20.04 with i3wm, my shell is zsh, and here are the commands i used (i modified them from this site and this site):

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 10
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python2.6 10
sudo update-alternatives --config python
sudo update-alternatives --config python3

For what I remember my previous python version was somewhere around 3.7.

If you prefer, here are the specs from above:

  • OS: Ubuntu 20.04
  • Shell: zsh (oh-my-zsh)
  • WM: i3
  • Terminal: gnome-terminal

Important: Please remember I do not have access to a terminal. I have still not tried recovery mode, but if you have a non-termianl based solution, it is preferred.

Hatchery answered 14/8, 2021 at 15:56 Comment(6)
I don't know how it works for Linux but at least on Windows you have to add Python to the PATH, also did you install Python2.6 too: --install /usr/bin/python python /usr/bin/python2.6 10?Wrung
Well, I have python in the "path", but I didn't have 2.6... That might be a problem, but why the terminal won't open?Hatchery
you certainly don't need Python2.6 so that can be uninstalled, why did you follow the instructions word for word? you had to adjust and not install 2.6. why the terminal doesn't open? no ideaWrung
There are OS tools which use Python 3.8 -- the version which comes with Ubuntu 20.04 -- and those tools may not work right or at all with 3.10 so it's not recommended -- to my knowledge -- to change too much. Another solution, possibly easier to manage, to the various versions of Python and dependencies is to use something like pipenv.Joni
I have already done it, though. I don't know how to undo it and I don't have access to shells...Hatchery
how on earth is this a thing - python is 30 years old!Dart
H
11

Just found a way to undo it. If you encounter the same problem, here is what I did:

Ctrl+Alt+Fn and a few F buttons (F1, F2, F3...) until I got to a tty menu. I logged in as myself (not root), and ran sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 to make the default python 2.8 with sudo update-alternatives --config python3 again. Then it worked properly.

Hatchery answered 14/8, 2021 at 17:49 Comment(0)
P
7

None of the above Solutions worked for me. However after searching a lot for an hour,

(Replace the Python version which was earlier present on your system, instead of 3.8)

sudo apt reinstall python3 python3-minimal python3.8 python3.8-minimal

this command did the magic!

(PS - Make sure you haven't changed anything in the usr/bin/gnome-terminal file) First line should be #!/usr/bin/python3

Lesson Learnt - Dont upgrade your OS Python Version manually EVER!

Protochordate answered 7/9, 2023 at 6:1 Comment(1)
This is the most useful answer that i had. Work fine on Ubuntu 22.04LTSMisjudge
P
6

Edited

New Answer

I found a better way to install your preferred python version. It's more stable and more secure than using ppa:deadsnakes/ppa repository.

Sure now this is not a direct answer to the problem you had anymore. But I am editing this answer here in hope to help you and anyone that may want to install python3.10 in a machine that does not come with it installed by default.

You can use asdf, which is a tool version manager. With it you may install any python version you want, independent of your OS. It is gonna be more verbose, but works perfectly well, without any conflict with some pre-installed python version.

To avoid problems when installing asdf and python, install the following packages:

sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

Then run:

sudo apt update && sudo apt upgrade

to make sure everything is up to date.

Installing asdf

To install asdf, first we clone from the repository and the branch of asdf version we want (Please note that the version specified in the end of the command may change. I just followed the documentation):

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0

Now you only got to add a few lines to the end of your script configuration file. It may change according to your shell, but again, check the documentation for specific instructions (including zsh).

To find out what kind of terminal you're using, you can run:

echo $SHELL

If your're using bash then you can add the following to the end of your ~/.bashrc (yes, the dots are included):

. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

After that, you just have to restart your terminal.

Installing python3.10 (or any version you want)

Now with asdf installed, you should install a plugin to manage multiple python versions. To do that, just run the command:

asdf plugin-add python

To globally install python3.10.4 in your system, run:

asdf install python 3.10.4

And then:

asdf global python 3.10.4

Lastly, run:

asdf reshim

This last command is a somewhat refresh for asdf to work properly after globally installing libraries. Run it whenever you install something with asdf, just to be sure.

No need to worry about running this command after installing some package or module with pip though (well, at least I never had).

Credits to Kenzie Academy. Learned it there.


Old Answer

I ran exactly into the same problem. I found the answer here.

At first, I tried to simply open the gnome-terminal file without a terminal and change it, but it didn't work, because using a GUI I had no sudo permissions. So the workaround that worked for me and I expect that may work for you, was to open the file with VSCode and then used the VSCode integrated terminal to run the following command:

sudo nano /usr/bin/gnome-terminal

Of course you don't have to use nano, you could use vim or something else. Anyway, once there, you can change the first line of the file, which is a comment, from

#!/usr/bin/python3

to

#!/usr/bin/python3.8

Ubuntu 20.04 is well compatible with python3.8, so that's why I suggested you putting python3.8 there but you could surely test if some other version works.

This is not a way to go back to python3.8. You will still have the add-ons of python3.10.

Pronounce answered 15/4, 2022 at 13:50 Comment(0)
P
0

I was facing the exact same issue and I had performed similar steps to reach the same. I tried @Rafael's response but did not notice any change. I could not open terminal but VSCode terminal was working. I noticed vscode was using an updated python. I fixed it by removing existing symbolic link and creating a new one. Terminal opened instantly.

OS: Ubuntu 20.04
Shell : zsh (Oh-my-zsh)

sudo rm /usr/bin/python3 
sudo ln -s /usr/bin/python3.8 /usr/bin/python3
Prithee answered 16/10, 2023 at 17:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.