To install python in ubunty first of all you need to install prerequisites.
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Then you need to download Python and extract downloaded package.
$ cd /usr/src
$ sudo wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
$ sudo tar xzf Python-3.6.2.tgz
Next step is compile Python source.
$ cd Python-3.6.2
$ sudo ./configure
$ sudo make altinstall
And finally check python version.
python3.6 --version