Skip to content

Instantly share code, notes, and snippets.

@mzpqnxow
Last active October 18, 2023 04:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzpqnxow/bccc91be512a04dc6aeaa1375492672e to your computer and use it in GitHub Desktop.
Save mzpqnxow/bccc91be512a04dc6aeaa1375492672e to your computer and use it in GitHub Desktop.
Patch to statically link OpenSSL into Python3.8

Statically Linking OpenSSL Into Python3.8

EDIT/NOTE: Please see the comment below from @oferchen, this is supported properly in the build system now

Get the patch file (python3-static-link-openssl.patch) and put it in your working directory

$ wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tar.xz
$ tar -xvf Python-3.8.12.tar.xz && cd Python-3.8.12
$ patch -p1 < ../python3-static-link-openssl.patch
$ ./configure ... --with-openssl=/opt/openssl-1.1.1k --enable-static-openssl
$ make -j && sudo make install

Verifying Success

You can verify OpenSSL was statically linked using the following

$ strace -o LOG python3 -c 'import ssl'
$ grep libssl LOG | wc -l
0
$
@oferchen
Copy link

with recent version of python you can set the environment variable PY_UNSUPPORTED_OPENSSL_BUILD=static

@mzpqnxow
Copy link
Author

mzpqnxow commented Jun 1, 2022

with recent version of python you can set the environment variable PY_UNSUPPORTED_OPENSSL_BUILD=static

That's very convenient, thanks!

Doing this back in the Python 2.x days for the first time (before I understood how the module config/build/linking worked) was a big barrel of fun. It's nice to see this being properly supported now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment