The Ubuntu operating systems from 14.X onwards all have python 3.x interpreter bundled. H
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
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
you should see a response similar:
Install Python 3 if not installed on Ubuntu
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
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.
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
The bash_aliases file will automatically be picked up the next time you source your
~/.bashrc file or reopen a terminal window because there is already a line in your
~/.bashrc that checks for the existence of the file then loads it if it exists.
# Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi
If you have ensured this line is present in your bash profile then refresh your terminal again using
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
The you can test using
We simply covered how you can configure Python3 as the default python interpretter on your Ubuntu Desktop.