Build Python 3.7 from Source - part 2

Install in Local System

You can select one of the following options

Install as Alternative Python Interpreter

You can install as alternative python without updating the main one:

Build python - alternative python
 ~/py/Python-3.7.2# sudo make altinstall
   ...

Now we can use the built python as python3.7:

Build python - alternative python
 ~/# which python3.7 && python3.7 --version
 /usr/local/bin/python3.7
 Python 3.7.2

Note that python3 is unchanged. For example : we can still use the main one, if already installed:

Build python - alternative python
 ~# which python3 && python3 --version
 /usr/bin/python3
 Python 3.6.7

Install as Main Python Interpreter

You can install as the main python interpreter:

Build python - main python
 ~/py/Python-3.7.2# sudo make install
   ...

Now we can use the built interpreter as python3:

Build python - main python
 ~/# which python3 && python3 --version
 /usr/local/bin/python3
 Python 3.7.2

We can also use the built python explicitly as python3.7:

Build python - main python
 ~/# which python3.7 && python3.7 --version
 /usr/local/bin/python3.7
 Python 3.7.2

Note, that you can use the previous python by calling it explicitly. For example:

Build python - main python
 ~/# which python3.6 && python3.6 --version
 /usr/bin/python3.6
 Python 3.6.7

Create a deb Package and Install via dpkg

You can create a deb package which can be installed via the apt and dpkg tools:

Build python - deb package
 ~/py/Python-3.7.2# sudo checkinstall make altinstall
   ...
 The package documentation directory ./doc-pak does not exist.
 Should I create a default set of package docs?  [y]: y
 ...

Enter the description for the package and change the package properties as needed:

Build python - deb package
 ...
 Please write a description for the package.
 End your description with an empty line or EOF.
 >> My customized python
 >>
 ...
 0 -  Maintainer: [ admin@company.com ]
 1 -  Summary: [ My customized python ]
 2 -  Name:    [ my-python ]
 3 -  Version: [ 3.7.2 ]
 4 -  Release: [ 1 ]
 5 -  License: [ GPL ]
 6 -  Group:   [ checkinstall ]
 7 -  Architecture: [ amd64 ]
 8 -  Source location: [ Python-3.7.2 ]
 9 -  Alternate source location: [  ]
 10 - Requires: [  ]
 11 - Provides: [ python ]
 12 - Conflicts: [  ]
 13 - Replaces: [  ]
 Enter a number to change any of them or press ENTER to continue: 
   ...
 Some of the files created by the installation are inside the build
 directory: /root/py/Python-3.7.2

 You probably dont want them to be included in the package,
 especially if they are inside your home directory.
 Do you want me to list them?  [n]: n
 Should I exclude them from the package? (Saying yes is a good idea)  [y]:

 Copying files to the temporary directory...
 ...
 Copying files to the temporary directory...OK
 Stripping ELF binaries and libraries...OK
 Compressing man pages...OK
 Building file list...OK
 Building Debian package...
 Installing Debian package...OK
   ...
 **********************************************************************
   Done. The new package has been installed and saved to
  /root/py/Python-3.7.2/my-python_3.7.2-1_amd64.deb
  You can remove it from your system anytime using:
       dpkg -r my-python
 **********************************************************************

Now, the package is installed:

Build python - deb package
 ~/# which python3.7 && python3.7 --version
 /usr/local/bin/python3.7
 Python 3.7.2
 ~# apt search my-python
 Sorting... Done
 Full Text Search... Done
 my-python/now 3.7.2-1 amd64 [installed,local]
   My customized python

You can easily remove the package with one step:

Build python - deb package
 ~/# apt -y remove my-python
 ...
 Removing my-python (3.7.2-1) ...
 ...

You can install the built package in multiple machines:

Build python - deb package
 ~/# apt install -y ~/py/Python-3.7.2/my-python_3.7.2-1_amd64.deb
   ...

Summery

Building python 3.7 form source on ubuntu systems is straightforward task. The third option - creating and installing a deb package - will help you to manage your builds easily. It will also allow you to install the resulting customized python package upon multiple machines.