Psycopg2 ld: library not found for -lssl

The error “ld: library not found for -lssl” is related to the missing OpenSSL library when trying to install or use the psycopg2 library in Python. OpenSSL is required by psycopg2 for establishing secure connections using SSL/TLS.

Here is a detailed explanation of the solution:

  1. First, make sure you have OpenSSL installed on your system. You can check by running the following command in your terminal:
    openssl version

    If OpenSSL is not installed, you need to install it before proceeding further. The installation method varies by operating system, so refer to the OpenSSL documentation or your package manager instructions.

  2. If OpenSSL is already installed, the error could be due to the missing or incorrect path to the OpenSSL library. You can try providing the correct path to the library in your system by setting the LD_LIBRARY_PATH environment variable. Use the following command:
    export LD_LIBRARY_PATH=/path/to/openssl/library:$LD_LIBRARY_PATH

    Replace “/path/to/openssl/library” with the actual path to the OpenSSL library on your system. This command adds the specified path to the library search path.

  3. If setting the LD_LIBRARY_PATH does not solve the issue, you might need to specify the library path directly during the installation or compilation of psycopg2. You can do this by setting the LDFLAGS environment variable. Use the following command:
    export LDFLAGS="-L/path/to/openssl/library"

    Replace “/path/to/openssl/library” with the actual path to the OpenSSL library on your system.

  4. Once you have set the environment variables, try installing or using psycopg2 again. If the installation or usage succeeds without any errors, then the issue is resolved.

Leave a comment