Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Python 3.7 on Ubuntu 14.04 with pyenv

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?

like image 951
Daniel Goldberg Avatar asked Aug 10 '26 21:08

Daniel Goldberg


1 Answers

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.

like image 71
Daniel Goldberg Avatar answered Aug 14 '26 19:08

Daniel Goldberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!