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.
Related
I want to switch my python version from 3.9.6 to 3.10 in paperspace. But it doesn't work.
So I need your help.
device info
$root#nu1mmmnfz5:/notebooks/LoRA# cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.5 LTS"
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$root#nu1mmmnfz5:/notebooks/LoRA# which python
/usr/local/bin/python
$root#nu1mmmnfz5:/notebooks/LoRA# ls /usr/local/bin/ | grep python
ipython
ipython3
python
python3
$ apt -y install python3.10
これが上手く入らないので苦戦しておりました。
$ python -V
Python 3.9.16
$ which python
/usr/local/bin/python
$ which python3
/usr/local/bin/python3
$ which python3.10
/usr/bin/python3.10
There are two, 'usr/local/bin' and 'usr/bin', and 'apt -y install python3.10' has gone into 'usr/bin'.
Tried
$apt update -y
$apt upgrade -y
$apt -y install python3.10
update-alternatives
You can install pyenv and you will be able to switch versions at will.
https://github.com/pyenv/pyenv
the best practice is not to change the system python version manually since many system services depend on it.
Also you should not install personal package using pip with root privilige for the same reason unless you know what it does.
you can use a version management to control the python env list like pyenv or conda
you can use update-alternatives to control python version
https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
maybe you should set the priority 0 or the same number
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 0
sudo update-alternatives --config python
[sudo] password for wz:
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.11 0 auto mode
1 /usr/bin/python2.7 0 manual mode
* 2 /usr/bin/python3.11 0 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode
I installed python 3.8 in my kali linux OS, but when I type python in kali linux terminal it showing like this
> Python 2.7.18 (default, Apr 20 2020, 20:30:41)
How can I set Python 3.8 as my default?
Hope this answers your question.
The easiest way would be to run alias python=python3 .
So, now if you run the command python it will load python3 instead of python while being under the same alias/command python.
What I usually do is install non-default versions of programs under /usr/local. Then I configure the file $HOME/.bash_profile so that the $PATH variable has /usr/local/bin first, before /usr/bin and /bin (which might actually be the same physical directory on your system).
$HOME/.bash_profile:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# PATH starts with...
PATH="/usr/local/bin"
# add $HOME/bin if it exists...
if [ -d "${HOME}/bin" ]; then
PATH="${PATH}:${HOME}/bin"
fi
# These should exist, add them as fall back....
PATH="${PATH}:/bin:/usr/bin:/sbin:/usr/sbin"
# Some custom locations last
if [ -d /usr/local/arm-elf/bin ]; then
PATH="${PATH}:/usr/local/arm-elf/bin"
fi
if [ -d /opt/local/bin ]; then
PATH="${PATH}:/opt/local/bin"
fi
This has the effect of making anything located in /usr/local/bin the default when I am using an interactive shell, and letting the system defaults remain in effect otherwise.
first, check if you have python3.8 installed
use
ls /usr/bin/python*
then check for an alternative python version using
update-alternatives --list python
if the output of python3.8 is set to 2
To set the default python command to run python3.8
use this to create a persistent symlink
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
the 2 depends on your python alternatives
then
python --version
First remove python 2.7.18
Type >> sudo apt purge -y python2-minimal
install python latest version
Type >> sudo apt install -y python3-pip
latest version of python is installed!
This question already has answers here:
Installed Python 3.8 on Ubuntu, but it's not the default
(3 answers)
Closed 2 years ago.
When I type python --version in my terminal, it shows Python 3.8.5, but when I type python3 --version, it shows Python 3.6.9. I want to create a virtual environment using python3 -m venv .venv with the version 3.8.5, but because of the fact that my default python3 version is the 3.6.9, it's creating a virtual environment using 3.6.9 as it's version. How do I change my default python3 version?
The python and python3 commands are usually soft links to the actual executables and you can change the targets. For example:
Firstly, find out where python 3.6 and python 3.8 are located:
# which python
/usr/bin/python
# ls -l /usr/bin/python
/usr/bin/python -> python3.8
# which python3
/usr/bin/python3
# ls -l /usr/bin/python3
/usr/bin/python3 -> python3.6
Then, change the soft links:
# rm /usr/bin/python3
# ln -s /usr/bin/python3.8 /usr/bin/python3
Run this Command in your terminal
sudo update-alternatives --config python
You'll get choice prompt, enter selection number of your desired python version.
But if this shows an error like this: update-alternatives: error: no alternatives for python3
Then you have to update your update-alternatives, then you will be able to set your default python version.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6.9
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8.5
Now run below command to set default python
sudo update-alternatives --set python /usr/bin/python3.8
I setup my server using python bottle & mod_wsgi
my bottle script are all writing by python3.4 but the apache2 server using by default python2.7.6 ?
is there a way to make the python3.4 the default python on apache2
I'm stock right now
I think you have installed mod_wsgi for python2 with this command:
sudo apt-get install libapache2-mod-wsgi
But if you want to use mod_wsgi with python3, you should install correct mod_wsgi with this command:
sudo apt-get install libapache2-mod-wsgi-py3
To change a python version on per user basis you simply create an alias within user's home directory. Open ~/.bashrc file and add new alias to change your default python executable:
alias python='/usr/bin/python3.4'
Once you make the above change, re-login or source your .bashrc file:
$ . ~/.bashrc
Check your default python version:
$ python --version
Python 3.4.2
Change python version system-wide
To change python version system-wide we can use update-alternatives command. Logged in as a root user, first list all available python alternatives:
# update-alternatives --list python
update-alternatives: error: no alternatives for python
The above error message means that no python alternatives has been recognized by update-alternatives command. For this reason we need to update our alternatives table and include both python2.7 and python3.4:
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
# update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
The --install option take multiple arguments from which it will be able to create a symbolic link. The last argument specified it priority means, if no manual alternative selection is made the alternative with the highest priority number will be set. In our case we have set a priority 2 for /usr/bin/python3.4 and as a result the /usr/bin/python3.4 was set as default python version automatically by update-alternatives command.
# python --version
Python 3.4.2
Next, we can again list all python alternatives:
# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.4
From now on, we can anytime switch between the above listed python alternative versions using below command and entering a selection number:
# update-alternatives --config python
So, I'd like to have Python 2.7.6 when I open the idle (that is the one pre-installed on Ubuntu); instead, the idle opens with the one that I have installed (2.7.5).
How can I do that?
Try
sudo update-alternatives --config python
and see the update-alternatives man page. If Ubuntu does not offer the alternatives automatically, you'll have to add them yourself, e.g.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.5 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.5 20