Skip to content

Instantly share code, notes, and snippets.

@daryltucker
Last active July 15, 2022 22:47
Show Gist options
  • Save daryltucker/ff8c82c2c1b8092884dd53861cbec4da to your computer and use it in GitHub Desktop.
Save daryltucker/ff8c82c2c1b8092884dd53861cbec4da to your computer and use it in GitHub Desktop.
Build latest stable Python 3.x for WSL (Windows Subsystem for Linux)

The WSL OpenSSL libraries are missing headers, preventing actually using them to compile anything.

  1. Grab OpenSSL source and checkout latest stable version (1.*)
  2. Build and Install OpenSSL
  3. Grab Python source and checkout latest stable version (3.*)
  4. Build and Install Python w. OpenSSL available.

TIP: Be sure to use the \\wsl$\ filesystem, and link out from that, vs creating a sym-link from Windows into WSL. If your git or other operations are slow, look into this.

#!/bin/bash
# @daryltucker
# build-python3-wsl.sh
sudo apt install -y git build-essential checkinstall pkg-config zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev libc6-dev tk-dev liblzma-dev uuid-dev curl wget
FILE="/etc/ld.conf.so"
LINE="/usr/local/lib"
grep -qF -- "$LINE" "$FILE" || echo "$LINE" | sudo tee -a "$FILE"
mkdir -p ~/src
cd ~/src
git clone https://github.com/openssl/openssl.git; cd openssl
git fetch -a
LATEST_TAG=$(git tag -l --format="%(creatordate:raw) %(refname)" | grep "OpenSSL_1"| sort -r | head -n1 | cut -d' ' -f3)
git checkout "$LATEST_TAG"
./config shared --prefix=/usr/local/
make -j $(expr $(nproc --all) - 2)
sudo ldconfig
cd ~/src
git clone https://github.com/python/cpython; cd cpython
git fetch -a
LATEST_TAG=$(git tag -l --format="%(creatordate:raw) %(refname)" | grep -v "rc" | grep 'v3.' | grep -E '.*\.[0-9]+$'| sort -r | head -n1 | cut -d' ' -f3)
git checkout "$LATEST_TAG"
LDFLAGS="$(pkg-config --libs openssl)" ./configure --enable-optimizations --with-lto --enable-shared
make -j $(expr $(nproc --all) - 2)
sudo make install
sudo ldconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment