Upgrading python 3.5 to python 3.6 - Ubuntu - python

This is the first time I am working with python.
I am using ubuntu 16.04 system.
I am trying to change default python 3.5 to python 3.6
I am following this link to achieve this.
But I am getting the following error when I fire the command :
sudo update-alternatives --config python3
Error : bash: /usr/bin/python3: Too many levels of symbolic links
Please refer the screenshot of the steps which I followed and the commands that are executed.
I have first fired update and upgrade command.
I am not able to understand root cause of the issue, since I am new to python and its environment.
Thank you

follow below steps:-
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6

Following command worked for me:
sudo apt-get -f upgrade python3.6

Answers here seem a bit out of date, mainly because the PPA no longer exists. This is what worked for me (relying on one of the links posted in some of the question comments, among others):
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
(now we have both versions, need to switch the "toggle")
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 0
Mind the trailing 0.

Related

Installed python3.9 not showing in linux

I installed python 3.9 following the steps in this link.
sudo apt update
sudo apt install python3.9
python3.9
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.[old-version] 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
sudo update-alternatives --config python3
However, it's throwing an error that python3.9 not found on the 3rd point. Also, I noticed the python3.9 on installation using the 2nd point is showing Note, selecting 'postgresql-plpython3-9.5' for regex 'python3.9'.
Complete message is
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'postgresql-plpython3-9.5' for regex 'python3.9'
The following packages were automatically installed and are no longer required:
linux-aws-headers-4.4.0-1104 linux-aws-headers-4.4.0-1105 linux-aws-headers-4.4.0-1106 linux-aws-headers-4.4.0-1107 linux-aws-headers-4.4.0-1109 linux-aws-headers-4.4.0-1110 linux-aws-headers-4.4.0-1111
linux-aws-headers-4.4.0-1112 linux-aws-headers-4.4.0-1113 linux-aws-headers-4.4.0-1114
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
postgresql-plpython3-9.5
0 upgraded, 1 newly installed, 0 to remove and 56 not upgraded.
Need to get 0 B/40.6 kB of archives.
After this operation, 166 kB of additional disk space will be used.
Selecting previously unselected package postgresql-plpython3-9.5.
(Reading database ... 362651 files and directories currently installed.)
Preparing to unpack .../postgresql-plpython3-9.5_9.5.25-0ubuntu0.16.04.1_amd64.deb ...
Unpacking postgresql-plpython3-9.5 (9.5.25-0ubuntu0.16.04.1) ...
Processing triggers for postgresql-common (173ubuntu0.3) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Setting up postgresql-plpython3-9.5 (9.5.25-0ubuntu0.16.04.1) ...
Why is it setting up postgresql-plpython3-9.5 and how can I prevent it from doing so?
The Problem:
The deadsnakes ppa is no longer available for Ubuntu Xenial. That's the reason you cannot install python3.9. See this issue. You will have to compile from source or upgrade your server to a supported version of Ubuntu.
Solution: build it yourself
If you are not able to upgrade your system, you could instead use pyenv to install any given python version as described below. For this a new version of openssl needs to be installed for python version >= 3.8
# install dependencies
apt update
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev liblzma-dev git
# download and compile openssl
curl -L https://www.openssl.org/source/openssl-1.1.1s.tar.gz | (cd /usr/src; tar xz)
cd /usr/src/openssl-1.1.1s && ./config --prefix=/usr/local && make -j4 && make install
# download and configure pyenv
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
echo >> ~/.bashrc # add new-line.
echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
# build python 3.9.16 with pyenv
CONFIGURE_OPTS="--with-openssl=/usr/local --with-openssl-rpath=auto" pyenv install 3.9.16
# build python 3.10.9 with pyenv
CONFIGURE_OPTS="--with-openssl=/usr/local --with-openssl-rpath=auto" pyenv install 3.10.9
You may have it already installed
try running $ python3 --version
to see what python version your running.
If its not installed try running $ sudo apt-get update then run $ sudo apt-get install python3.9 to install python3.9
Hopefully this will help
You will need to add the deadsnakes repo.
sudo add-apt-repository ppa:deadsnakes/ppa
After that you can follow the steps in your question.
If you still have the same issues after adding the deadsnakes repo, it probably means your running an unsupported version of linux. You might then have to install Python 3.9 from source, you can check this answer on how to do that.

How to set default Python version without --update-alternatives

I have Python3.6 and Python3.8 installed on Ubuntu 18.04. When I execute python3 -V I get python3.8.0, which is correct. That's currently my default Python.
I used the Ubuntu 18.04 package repository when I installed Python3.6 and Python3.8. I just built Python3.10 from source and I want to set that as the default now. The canonical way to change is with --update-alternatives, but I did not do that when I installed Python3.6 and Python3.8, so when I execute:
update-alternatives --query python
update-alternatives: error: no alternatives for python
Python3.8 is in /usr/bin/python3.8 and Python3.10 is in /usr/local/bin/python3.10.
According to what I have read on the net, I should do this:
$ sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3.8
$ sudo update-alternatives --install /usr/local/bin/python python /usr/local/bin/python3.10
Then I select the default with sudo update-alternatives --config python.
Because I currently don't have any alternatives but I was somehow able to switch from Python3.6 to Python3.8 (I don't remember how), will the commands above cause any problems? Is there a problem in the different locations for 3.8 (/usr/bin/) vs 3.10 (/usr/local/bin/) and what will be the effect of the symlink for 3.10 going into /usr/local/bin/ where it's already located.
Naturally I could just try it, but if there is an issue I'm not sure how to back out of it if it goes wrong. I've gotten a lot of differing information on the net.
Thanks for any help.
I have answered my own question. First, I did have alternatives, but as Ubuntu defaults to Python2 (please Ubuntu change that -- the world has moved on), the command is sudo update-alternatives --config python3:
$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.8 2 auto mode
1 /usr/bin/python3.6 1 manual mode
2 /usr/bin/python3.8 2 manual mode
Note the line "providing /usr/bin/python3." That means the Python symlinks for Python 3 are in /usr/bin/python3. So I add the new one:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 3
That makes Python 3.10 priority 3, the highest priority. Then:
$ python3 --version
Python 3.10.0
I hope that helps someone in the future.

Update a raspberry pi to python 3.9

Been attempting to update a 2 year old, untouched raspberry pi to be able to run a pip module that only runs on 3.6+. I updated the operating system and I've been attempting to update python following this guide but I get to the last stage and it returns python 3.5.3. (note: i added the line to the bottom of the file because i couldn't find it)
I also tried
sudo update-alternatives --config python but it returned update-alternatives: error: no alternatives for python
First of all, try removing your current python version:
To know your version:
python --version
Then do this to remove Python:
sudo add-apt-repository --remove ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get remove --purge pythonX.X
And finally, enable your repositories again, and install Python 3.9:
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9

Python Upgrading leads to terminal... not opening

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.
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.
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.

How to use virtualenv with python3.6 on ubuntu 16.04?

I'm using Ubuntu 16.04, which comes with Python 2.7 and Python 3.5. I've installed Python 3.6 on it and symlink python3 to python3.6 through alias python3=python3.6.
Then, I've installed virtualenv using sudo -H pip3 install virtualenv. When I checked, the virtualenv got installed in "/usr/local/lib/python3.5/dist-packages" location, so when I'm trying to create virtualenv using python3 -m venv ./venv1 it's throwing me errors:
Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
What should I do?
We usually use $ python3 -m venv myvenv to create a new virtualenv (Here myvenv is the name of our virtualenv).
Similar to my case, if you have both python3.5 as well as python3.6 on your system, then you might get some errors.
NOTE: On some versions of Debian/Ubuntu you may receive the following error:
The virtual environment was not created successfully because ensure pip is not available. On Debian/Ubuntu systems, you need to install the python3-venv package using the following command.
apt-get installpython3-venv
You may need to use sudo with that command. After installing the python3-venv package, recreate your virtual environment.
In this case, follow the instructions above and install the python3-venv package:
$ sudo apt-get install python3-venv
NOTE: On some versions of Debian/Ubuntu initiating the virtual environment like this currently gives the following error:
Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
To get around this, use the virtualenv command instead.
$ sudo apt-get install python-virtualenv
$ virtualenv --python=python3.6 myvenv
NOTE: If you get an error like
E: Unable to locate package python3-venv
then instead run:
sudo apt install python3.6-venv
Installing python3.6 and python3.6-venv via ppa:deadsnakes/ppa instead of ppa:jonathonf/python-3.6 worked for me
apt-get update \
&& apt-get install -y software-properties-common curl \
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt-get update \
&& apt-get install -y python3.6 python3.6-venv
First make sure you have python3.6 installed, otherwise you can install it with command:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.6
Now install venv i.e
sudo apt-get install python3.6-venv python3.6-dev
python3.6 -m venv venv_name
You can install python3.7/3.8 and also respective venv with above comman, just replace 3.6 with 3.X
I think that a problem could be related to the wrong locale.
I added to the /etc/environment the following lines to fix it:
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
You need to source the file from you bash with this command:
source /etc/environment
if you get following irritating error:
E: Unable to locate package python3-venv
try this commands:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
those worked for me.hope it helps !

Categories

Resources