Unable to set default python version to python3 in ubuntu
EDIT:
I wrote this when I was young and naive, update-alternatives
is the better way to do this. See @Pardhu's answer.
Outdated answer:
Open your .bashrc file
nano ~/.bashrc
. Typealias python=python3
on to a new line at the top of the file then save the file with ctrl+o
and close the file with ctrl+x. Then, back at your command line typesource ~/.bashrc
. Now your alias should be permanent.
How to set default python3 to python 3.9 instead of python 3.8 in Ubuntu 20.04 LTS
You should be able to use python3.9 -m pip install <package>
to run pip with a specific python version, in this case 3.9.
The full docs on this are here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
If you want python3 to point to python3.9 you could use the quick and dirty.
alias python3=python3.9
EDIT:
Tried to recreate your problem,
# which python3
/usr/bin/python3
# python3 --version
Python 3.8.10
# which python3.8
/usr/bin/python3.8
# which python3.9
/usr/bin/python3.9
Then update the alternatives, and set new priority:
# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
# 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.9 2 auto mode
1 /usr/bin/python3.8 2 manual mode
* 2 /usr/bin/python3.9 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
Check new version:
# ls -alith /usr/bin/python3
3338 lrwxrwxrwx 1 root root 25 Feb 8 14:33 /usr/bin/python3 -> /etc/alternatives/python3
# python3 -V
Python 3.9.5
# ls -alith /usr/bin/pip3
48482 -rwxr-xr-x 1 root root 367 Jul 13 2021 /usr/bin/pip3
# pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)
Hope this helps (tried it in wsl2 Ubuntu 20.04 LTS)
Permanently change the default Python3 version in Linux (Ubuntu on Windows)
You can always usesudo update-alternatives --config python3
and then select your python3 version.
That should solve your issue without needing to do weird configs.
How do I change my default python 3 having more than one version installed (Ubuntu 18.04)?
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
how to make virtualenv see the default python version on Ubuntu
You can use the below command for ensuring that virtualenv refers to python3.8 by default
python3.8 -m virtualenv myenv
Related Topics
How to Get a Raw, Compiled SQL Query from a SQLalchemy Expression
Classification Using Movie Review Corpus in Nltk/Python
Python Urllib2 Basic Auth Problem
Search for "Does-Not-Contain" on a Dataframe in Pandas
How to Convert Strings in a Pandas Data Frame to a 'Date' Data Type
A Logarithmic Colorbar in Matplotlib Scatter Plot
Why Does My Pandas Dataframe Not Display New Order Using 'Sort_Values'
How to Use Raw Socket in Python
Running Infinite Loops Using Threads in Python
What Does "Bound Method" Error Mean When I Call a Function
Implement Matlab's Im2Col 'Sliding' in Python
Difference Between "Findall" and "Find_All" in Beautifulsoup
Getting Today's Date in Yyyy-Mm-Dd in Python
What Is the Advantage of a List Comprehension Over a for Loop
Dynamic Terminal Printing with Python
How to Make Environment Variable Changes Stick in Python
How to Extract Parameters from a List and Pass Them to a Function Call