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