Default Python version

Welcome! Both Python 2 and 3 are pre-installed in Ubuntu MATE. In 18.04, those versions are:

$ python --version
Python 2.7.15+

$ python3 --version
Python 3.6.8

Running the right one depends on the "shebang" at the top of the Python file you're trying to run, or the command is used to execute the file.

Python 2:

#!/usr/bin/python
#!/usr/bin/python2
#!/usr/bin/env python
#!/usr/bin/env python2

python /path/to/script

Python 3:

#!/usr/bin/python3
#!/usr/bin/env python3

python3 /path/to/script

In some distributions, python might run Python 3.x, and have python2 instead. Ubuntu has both python2 and python3, with python defaulting to 2.x.


While possible, I wouldn't recommend manually installing a version of Python 2.x or 3.x outside the distribution's repositories, as it can become a pain to maintain multiple versions of Python on the system, the libraries required by programs and can introduce inconsistency issues.

There is a tool called virtualenv that can be used to create isolated environments of Python.

:bulb: Tip - Ubuntu 19.10 that's being released on the 17th of October ships Python 2.7.16.