Call + (44) 0843 289 4539

Configure Python 3 as default on Ubuntu

The Ubuntu operating systems from 14.X onwards all have python 3.x interpreter bundled , however python 2.7.6 interpreter is still usually configured as the default interpreter.

In this post we’ll provide details on how to configure python 3.x as the default interpreter on your Ubuntu desktop computer.

In order to check which version of python is currently configured on your Ubuntu desktop simply execute the following command in a terminal window session

python --version

If most cases this will usually return the python version 2.7 because this is usually the default interpretter Ubuntu is shipped with, However, Python3 is also packaged and can be accessed.

To check if Python3 is installed on your release of simply open a terminal window and type

python3 --version

you should see a response similar:

Install Python 3

If you do not have python3 installed then you can install it using:

sudo apt update

sudo apt install python3

Due to the way most Linux distributions are handling the Python 3 migration, Linux users using the system Python without creating a virtual environment first should replace the python command python3 and the pip command with pip3 –user.

For simplicity going forward, we will install pip3

sudo apt install python3-pip


Configure python3 as default interpretter

To configure Python 3 as the default interpreter you need to configure an alias and point it to the python3 interpretter

Create a bash_aliases file, that will be used by the terminal window in future.

In your terminal window type in the following

echo "alias python=python3" >> ~/.bash_aliases

 

Once this is complete we will need refresh the current terminal window with the updated information. To do so simply.

source ~/.bash_aliases

 

Now when you type python in your terminal window you should see the version number of 3

If you ever need to alter your python version in future.

If you would like to change it back again in the future, you can simply edit the file using

echo "alias python=python2" >> ~/.bash_aliases

Then refresh your terminal again

source ~/.bash_aliases


Configure pip3

PIP is a package manager for Python packages. A package contains all the files you need for a module. Modules are Python code libraries you can include in your project.

In order to ensure you use the latest version of PIP for Python3 we will also need to install it and configure it as your default package management system.

in order to do so first ensure that is is installed

sudo apt install python3-pip

We can now edit the bash_aliases  again and add alias pip=pip3 to do so simply

echo "alias pip=pip3" >> ~/.bash_aliases
Refresh your terminal

source ~/.bash_aliases

 

The you can test using pip --version


We simply covered how you can configure Python3 as the default python interpretter on your Ubuntu Desktop.

Video


Follow Me

Gary Woodfine

Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Follow Me
%d bloggers like this: