Solve error – unable to set default python version to python3 in ubuntu

unable to set default python version to python3 in ubuntu is an issue which occurs in python when you do not know how to switch to python3.

In this article I am going to help you solve this error and understand the root of the problem, also I am presenting other possible solutions that may work if the main solution does not work for you.

Explaining the Error : unable to set default python version to python3 in ubuntu

First of all, the error usually occurs when you try to switch to python3 using a update-alternatives in a command for example, the goal is to set the default python version to python3.

Here is an example of the error message.

                                                                       #
ach@ach-lenovo-1015:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs <link> <name> <path> <priority>
Use 'update-alternatives --help' for program usage information.
                                                                       #

Bellow I will present multiple solutions some have worked for me and others have worked for other developers.

Solution 1 : configure Python 3.7 as the default interpreter

If we assume that you have Python 3.6 which is what a lot of people with this error have, PS: replace it with the version that troubles you.

Start by using apt-get to install Python 3.7 ( assuming you have linux ) like in the following command.

                                                                       #
sudo apt-get install python3.7
                                                                       #

Then, you can add the version you have and python 3.7 to update-alternatives. Using the commands bellow.

                                                                       #
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
                                                                       #

Finally, you should point python3 to python 3.7. Using the command bellow.

                                                                       #
sudo update-alternatives --config python3 Enter 2 for Python 3.7
                                                                       #

The solution above is good but if it does not solve the issue check out the one bellow.

Solution 2 : use an alias

First, you need an editor called gedit editor. If you have it then great.

If you don’t, you can get it from the following link: https://help.gnome.org/users/gedit/stable/

You need to add the following line to the bashrc file 

                                                                       #
alias python=python3
                                                                       #

First, you can get into the file using the gedit editor by using.

                                                                       #
gedit ~/.bashrc
                                                                       #

Now, run the command bellow.

                                                                       #
source ~/.bash_aliases or source ~/.bashrc
                                                                       #

The error should be gone, if the error persists try the following solution.

Solution 3 : unlink python3 then proceed

This is the last solution, I hope this gets rid of the issue.

Like in the examples above start by installing the version of python you want.

                                                                       #
sudo apt-install python3.7
                                                                       #

Run the following command to change the directory.

                                                                       #
cd /usr/bin
                                                                       #

You should now unlink python3 using the command bellow

                                                                       #
sudo unlink python3
                                                                       #

If that does not work you can try the same command, just remove the 3.

                                                                       #
sudo unlink python
                                                                       #

Finally you can link the current version by using the command.

                                                                       #
sudo ln -sv /usr/bin/python3.7 python
                                                                       #

I hope this guide solved your problem, thank you for reading.

Summing-up

The error Microsoft Visual C++ 14.0 or greater is required is not an unusual error in Python, I hope you solved it with some help from this article, remember errors are normal in our field, that is where the fun is, keep coding and keep creating, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/