Last active
March 1, 2025 01:31
-
-
Save molinav/1f3a50fbf645a1c0c8b4d2c00540155e to your computer and use it in GitHub Desktop.
Install almost all Python environments on Ubuntu 20.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# Copyright (c) 2020 Víctor Molina García | |
# MIT License | |
# | |
# Script to install Python environments 2.6+ and 3.2+ using PyEnv | |
# and the installation steps for OpenSSL 1.0.2 mostly based on the | |
# information available in the following link: | |
# http://www.linuxfromscratch.org/blfs/view/7.7/postlfs/openssl.html | |
# | |
# Tested on Ubuntu 20.04; bash is required because otherwise the PyEnv | |
# initialisation command fails. | |
# | |
# Set to exit on error. | |
set -e | |
cwd=$(pwd) | |
# Install basic dependencies. | |
echo "Installing basic dependencies..." | |
sudo apt-get install -y build-essential wget curl llvm git libssl-dev tk-dev \ | |
libncursesw5-dev libreadline-dev libsqlite3-dev \ | |
libffi-dev xz-utils zlib1g-dev libbz2-dev liblzma-dev | |
sudo apt-get install -y openssl ca-certificates | |
# Download and install OpenSSL 1.0.2. | |
openssl_name=openssl-1.0.2 | |
openssl_targz=$openssl_name.tar.gz | |
openssl_patch=$openssl_name-fix_parallel_build-1.patch | |
openssl_dir=$HOME/.local/opt/$openssl_name | |
openssl_inc=$openssl_dir/include | |
openssl_lib=$openssl_dir/lib | |
openssl_ssl=$openssl_dir/ssl | |
echo "Downloading OpenSSL..." | |
wget https://www.openssl.org/source/$openssl_targz | |
wget https://www.linuxfromscratch.org/patches/downloads/openssl/$openssl_patch | |
echo "Decompressing OpenSSL..." | |
tar -xf $openssl_targz | |
echo "Patching OpenSSL..." | |
cd $openssl_name | |
patch -Np1 -i ../$openssl_patch | |
echo "Installing OpenSSL..." | |
./config --prefix=$openssl_dir --openssldir=$openssl_dir/ssl --libdir=lib \ | |
-Wl,-rpath=$openssl_dir/lib shared zlib-dynamic | |
make | |
make install | |
cd $cwd | |
rm -rf $openssl_name | |
echo "Linking CA certificates..." | |
rmdir $openssl_ssl/certs && ln -s /etc/ssl/certs $openssl_ssl/certs | |
# Download PyEnv from its GitHub repository. | |
export PYENV_ROOT=$HOME/.local/share/pyenv | |
export PATH=$PYENV_ROOT/bin:$PATH | |
git clone https://github.com/pyenv/pyenv.git $HOME/.local/share/pyenv | |
eval "$(pyenv init -)" | |
echo "Installing all Pythons..." | |
# Install Python versions that can use OpenSSL v1.1. | |
pyenv install 3.9.0 | |
pyenv install 3.8.6 | |
pyenv install 3.7.9 | |
pyenv install 3.6.12 | |
pyenv install 3.5.10 | |
pyenv install 2.7.18 | |
# Install Python versions that require the elder OpenSSL v1.0.2. | |
export CFLAGS="-I$openssl_inc" | |
export LDFLAGS="-L$openssl_lib" | |
export LD_LIBRARY_PATH="$openssl_lib" | |
pyenv install 3.4.10 | |
pyenv install 3.3.7 | |
pyenv install 3.2.6 | |
pyenv install 2.6.9 | |
echo "Remember to set LD_LIBRARY_PATH=$openssl_lib in your .bashrc file:" | |
echo " LD_LIBRARY_PATH=$openssl_lib:\$LD_LIBRARY_PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ewertao Thanks! I have just updated the gist.