Compiling Python 3.7 and up on Ubuntu 14.04 doesn't work out of the box. This is because Ubuntu 14.04 is baselined on OpenSSL 1.0.1 and Python 3.7 requires OpenSSL 1.0.2 and up.
What is the best solution that doesn't involve 3rd party PPAs?
I didn't see a single definitive solution so I decided to write one on compiling from source without impacting the rest of the system.
You need two steps, one is building your own version of OpenSSL and the second is instructing pyenvto use it.
To install OpenSSL, run the following commands.
mkdir openssl
cd openssl
wget https://www.openssl.org/source/openssl-1.0.2u.tar.gz
tar -xzvf openssl-1.0.2u.tar.gz
cd openssl-1.0.2u
./config --prefix=$HOME/openssl --openssldir=$HOME/openssl shared zlib
make
make install
This installs the latest version on OpenSSL 1.0.2 (no more patches will be released) to your home directory. Now to install Python 3.7 using pyenv.
After you configure pyenv, run the following command
PATH="$HOME/openssl:$PATH" CPPFLAGS="-I$HOME/openssl/include" CFLAGS="-I$HOME/openssl/include/" LDFLAGS="-L$HOME/openssl/lib -Wl,-rpath,$HOME/openssl/lib" LD_LIBRARY_PATH=$HOME/openssl/lib:$LD_LIBRARY_PATH LD_RUN_PATH="$HOME/openssl/lib" CONFIGURE_OPTS="--with-openssl=$HOME/openssl" PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.7.5
You may add -O2 if you want faster run times.