7

I need to try python 3.7 with openssl-1.1.1 in Ubuntu 16.04. Both python and openssl versions are pre-release. Following instructions on how to statistically link openssl to python in a previous post, I downloaded the source for opnssl-1.1.1. Then navigate to the source code for openssl and execute:

./config
sudo make
sudo make install

Then, edit Modules/Setup.dist to uncomment the following lines:

SSL=/usr/local/ssl
_ssl _ssl.c \
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -L$(SSL)/lib -lssl -lcrypto

Then download python 3.7 source code. Then, navigate inside the source code and execute:

./configure
make
make install

After I execute make install I got this error at the end of the terminal output:

./python: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
generate-posix-vars failed
Makefile:596: recipe for target 'pybuilddir.txt' failed
make: *** [pybuilddir.txt] Error 1

I could not figure out what is the problem and what I need to do.

user9371654
  • 2,160
  • 16
  • 45
  • 78
  • 1
    you forgot to uncomment `_socket socketmodule.c` too but that won't solve your problem AFAIK – user3085931 May 09 '18 at 09:30
  • 2
    Your SSL libs -- if they're in `/usr/local/lib` (default location if you don't pass any other arguments to `./config` when compiling), make sure that location is in your `/etc/ld.so.conf`, and that you've run `ldconfig` to update the cache tracking shared library locations. – Charles Duffy May 26 '18 at 00:36
  • Beyond that, it's also helpful to check output of `ldd` to figure out why an executable can't be loaded. – Charles Duffy May 26 '18 at 00:36

3 Answers3

7

This has (should have) nothing to do with Python or OpenSSL versions.

Python build process, includes some steps when the newly built interpreter is launched, and attempts to load some of the newly built modules - including extension modules (which are written in C and are actually shared objects (.sos)).

When an .so is loaded, the loader must find (recursively) all the .so files that the .so needs (depends on), otherwise it won't be able to load it.

Python has some modules (e.g. _ssl*.so, _hashlib*.so) that depend on OpenSSL libs. Since you built yours against OpenSSL1.1.1 (the lib names differ from what comes by default on the system: typically 1.0.*), the loader won't be able to use the default ones.

What you need to do, is instruct the loader (check [Man7]: LD.SO(8) for more details) where to look for "your" OpenSSL libs (which are located under /usr/local/ssl/lib). One way of doing that is adding their path in ${LD_LIBRARY_PATH} env var (before building Python):

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/ssl/lib
./configure
make
make install

You might also want to take a look at [Python.Docs]: Configure Python - Libraries options (--with-openssl, --with-openssl-rpath).

Worth reading (probably):

CristiFati
  • 38,250
  • 9
  • 50
  • 87
2

What I have done to fix this :

./configure --with-ssl=./libssl --prefix=/subsystem
sed -i 's!^RUNSHARED=!RUNSHARED=LD_LIBRARY_PATH=/path/to/own/libssl/lib!' Makefile
make
make install

Setting LD_LIBRARY_PATH with export was not sufficient

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • I, too, was getting build errors with the LD_LIBRARY_PATH export, and this Makefile change worked for me. Centos 7, python 3.10.4 – Lou K May 23 '22 at 10:27
  • although having said that, I can't import ssl from the resulting python build – Lou K May 23 '22 at 10:50
  • I had upvoted this, but should have downvoted. stackoverflow won't let me change my vote. The problem with this change is it prevents python's lib-dynload from being created. – Lou K May 28 '22 at 10:18
-1

With Python-3.6.5 and openssl-1.1.0h i get stuck in the same problem. I have uncomment _socket socketmodule.c.

marianta
  • 49
  • 1
  • 6