Python: How can I tell if my python has SSL?
Question: How can I tell if my source-built python has SSL enabled? either

  * after running configure, but before compiling (best).
  * after compiling, when I can run the python.

Context:

  * a script that populates a bare linux box.
  * Prerequisite is to install openssl, so that Python can do https.
  * trying to detect if this prerequisite is not met.


Answer: If all you want to do is figure out if `openssl` is installed, you can parse
the output of `openssl version`:

    
    
    $ openssl version
    OpenSSL 1.0.2g-fips  1 Mar 2016
    

You can get [all sorts of
information](https://www.openssl.org/docs/manmaster/apps/version.html) from
`version`, for example, the directory where its stored:

    
    
    $ openssl version -d
    OPENSSLDIR: "/usr/lib/ssl"
    

As far as Python goes, I'm not sure how you can tell before running configure
(maybe check the contents of `config.log`?) but once Python is installed;
simply parse the output of `ssl.OPENSSL_VERSION`, like this:

    
    
    $ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
    OpenSSL 1.0.2g-fips  1 Mar 2016
    

For even more information, have a play with the `sysconfig` module, for
example:

    
    
    $ python -c "import sysconfig; print(sysconfig.get_config_var('CONFIG_ARGS'))"
    '--enable-shared' '--prefix=/usr' '--enable-ipv6' '--enable-unicode=ucs4' '--with-dbmliborder=bdb:gdbm' '--with-system-expat' '--with-computed-gotos' '--with-system-ffi' '--with-fpectl' 'CC=x86_64-linux-gnu-gcc' 'CFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security ' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'
    

