Building Python with SSL support in non-standard location Building Python with SSL support in non-standard location python python

Building Python with SSL support in non-standard location


You need to edit Modules/Setup.dist to specify the location of OpenSSL if it is not in the standard location. From Getting SSL Support in Python 2.5.1:

If you find yourself on a linux box needing ssl support in python (to use a client in things like httplib.HTTPSConnection or imaplib.IMAP4_SSL), then let me save you a couple of hours of hunting around the web (of course if you have found this then that means you've done some level hunting already!).

You'll know if you need ssl support compiled into your python installation if you get the following exception message: AttributeError: 'module' object has no attribute 'ssl'

In order to make that go away so you can continue happily slinging python code, you'll need to first make sure you have OpenSSL installed. By default it is installed from source at: /usr/local/ssl

If that directory doesn't exist, then grab the source package.

Do the standard:

tar zxf openssl-0.9.8g.tar.gzcd openssl-0.9.8g./configmakemake install

Then grab the python sources for 2.5.1 and: tar zxf Python-2.5.1.tgz && cd Python-2.5.1

Then you need to edit the Modules/Setup.dist:

204:# Socket module helper for SSL support; you must comment out the other205:# socket line above, and possibly edit the SSL variable:206:SSL=/usr/local/ssl207:_ssl _ssl.c \208:    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \209:    -L$(SSL)/lib -lssl -lcrypto

If you installed OpenSSL in the default locations you can just uncomment lines 206-209, then:

./configuremakemake install

Then verify your installation with:

python /usr/local/lib/python2.5/test/test_socket_ssl.pytest_rude_shutdown ...test_basic ...test_timeout ...

Make sure the changes to Modules/Setup.dist get picked up by cleaning the source root (e.g. make distclean) and run configure and make again.


On Linux Red Hat 7.7 x86_64, the following worked to install openssl-1.1.1d and Python-3.8.1 in my home directory (/home/unix/vangalen):

Install OpenSSLsource1 source2

cd ~wget https://www.openssl.org/source/openssl-1.1.1d.tar.gztar -xzf openssl-1.1.1d.tar.gzcd /home/unix/vangalen/openssl-1.1.1d./config --prefix=/home/unix/vangalen/openssl --openssldir=/home/unix/vangalen/opensslmakemake testmake install

Install Pythonsource2 source3 source4

cd ~wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgztar xf Python-3.8.1.tgz

Modify Python-3.8.1/Modules/Setup in a text editor. If this file doesn't exist you may need to go through a failed run first. Uncomment lines and adjust the alias for SSL in lines 206 to 213::

_socket socketmodule.c# Socket module helper for SSL support; you must comment out the other# socket line above, and possibly edit the SSL variable:SSL=/home/unix/vangalen/openssl_ssl _ssl.c \  -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \  -L$(SSL)/lib -lssl -lcrypto
cd ~/Python-3.8.1export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/unix/vangalen/openssl/lib./configure --prefix=/home/unix/vangalen/py-381 --with-openssl=/home/unix/vangalen/opensslmakemake testmake install


in the Bourne shell (/bin/sh or /bin/bash):

$ LD_LIBRARY_PATH=/usr/local/lib$ export LD_LIBRARY_PATH$ make

in the C-shell (/bin/csh or /bin/tcsh):

% setenv LD_LIBRARY_PATH /usr/local/lib% make