opensslhomebrewdyldpyenvlibssh2

openssl@1.1 not used? dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib


While attempting to install python via pyenv, I was hitting the a frustrating dynamic link error for openssl, even though I'd installed and configured openssl@1.1 via homebrew months prior:

$ pyenv install -v 3.8.2
pyenv: /Users/fire/.pyenv/versions/3.8.2 already exists
continue with installation? (y/N) y
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
/var/folders/c3/cmbbfq710rvdh4l82q2h_86ds4cblh/T/python-build.20200807114817.54648 ~/projects
Downloading Python-3.8.2.tar.xz...
-> https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/opt/libssh2/lib/libssh2.1.dylib
  Reason: image not found
/usr/local/bin/python-build: line 355: 55387 Abort trap: 6           aria2c --allow-overwrite=true --no-conf=true -o "${out}" ${ARIA2_OPTS} "$1" 1>&4
error: failed to download Python-3.8.2.tar.xz

BUILD FAILED (OS X 10.14.6 using python-build 20180424)

I'd double checked all of my paths for openssl@1.1, tried reinstalling pyenv via homebrew, etc., and nothing to this point had worked.


Solution

  • In short: Check the libraries referencing the missing dynamic library, and confirm you've re-built them after changing openssl versions as well.
    You can rebuild either via a version upgrade with brew upgrade or a reinstallation of the problematic package via brew reinstall.

    Why? Homebrew does not appear to consider libssh2 a dependent of openssl@1.1, and thus does not rebuild it automatically as it otherwise would.


    Investigatory debug process:

    After wracking my brain, google, and SO for an hour, I took yet another look at the failure:

    dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
      Referenced from: /usr/local/opt/libssh2/lib/libssh2.1.dylib
      Reason: image not found
    

    From there, I noticed that libssh2 was the cause of the failed reference:

      Referenced from: /usr/local/opt/libssh2/lib/libssh2.1.dylib
    

    On a whim, I checked the version of libssh2 homebrew had installed:

    $ brew info libssh2
    libssh2: stable 1.9.0 (bottled), HEAD
    C library implementing the SSH2 protocol
    https://libssh2.org/
    /usr/local/Cellar/libssh2/1.8.0 (182 files, 798.7KB) *
      Poured from bottle on 2018-11-14 at 17:45:34
    From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libssh2.rb
    License: BSD-3-Clause
    ==> Dependencies
    Required: openssl@1.1 āœ”
    ==> Options
    --HEAD
        Install HEAD version
    ==> Analytics
    install: 38,765 (30 days), 110,674 (90 days), 607,725 (365 days)
    install-on-request: 2,946 (30 days), 4,789 (90 days), 19,954 (365 days)
    build-error: 0 (30 days)
    

    Ah, that might be it! This was installed back in 2018!

      Poured from bottle on 2018-11-14 at 17:45:34
    

    One brew upgrade libssh2 later and we're in business

    ==> Upgrading 1 outdated package:
    libssh2 1.8.0 -> 1.9.0_1
    ==> Upgrading libssh2 1.8.0 -> 1.9.0_1
    ==> Downloading https://homebrew.bintray.com/bottles/libssh2-1.9.0_1.mojave.bottle.tar.gz
    ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/327c56ad6a54894e5ef9aa3019d2444d32f1d0fba80925940100e517dd3109c9?response-content-disposition=attachment%3Bfilename%3D%22libssh2-1.9.0_1.mojave.bottle.tar.gz%22&Policy
    ######################################################################## 100.0%
    ==> Pouring libssh2-1.9.0_1.mojave.bottle.tar.gz
    šŸŗ  /usr/local/Cellar/libssh2/1.9.0_1: 184 files, 942KB
    Removing: /usr/local/Cellar/libssh2/1.8.0... (182 files, 798.7KB)
    
    ...
    
    

    And from there, our initial problem is resolved:

    $ pyenv install -v 3.8.2
    pyenv: /Users/fire/.pyenv/versions/3.8.2 already exists
    continue with installation? (y/N) y
    python-build: use openssl@1.1 from homebrew
    python-build: use readline from homebrew
    /var/folders/c3/cmbbfq710rvdh4l82q2h_86ds4cblh/T/python-build.20200807115352.60918 ~/projects
    Downloading Python-3.8.2.tar.xz...
    -> https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
    
    08/07 11:53:54 [NOTICE] Downloading 1 item(s)
    [#25162c 0B/0B CN:1 DL:0B]
    
    08/07 11:53:55 [NOTICE] Allocating disk space. Use --file-allocation=none to disable it. See --file-allocation option in man page for more details.
    [#25162c 9.0MiB/17MiB(52%) CN:1 DL:9.8MiB]
    
    08/07 11:53:56 [NOTICE] Download complete: /private/var/folders/c3/cmbbfq710rvdh4l82q2h_86ds4cblh/T/python-build.20200807115352.60918/Python-3.8.2.tar.xz
    
    Download Results:
    gid   |stat|avg speed  |path/URI
    ======+====+===========+=======================================================
    25162c|OK  |   9.9MiB/s|/private/var/folders/c3/cmbbfq710rvdh4l82q2h_86ds4cblh/T/python-build.20200807115352.60918/Python-3.8.2.tar.xz
    
    Status Legend:
    (OK):download completed.
    /var/folders/c3/cmbbfq710rvdh4l82q2h_86ds4cblh/T/python-build.20200807115352.60918/Python-3.8.2 /var/folders/c3/cmbbfq710rvdh4l82q2h_86ds4cblh/T/python-build.20200807115352.60918 ~/projects
    Installing Python-3.8.2...
    python-build: use readline from homebrew
    python-build: use zlib from xcode sdk
    checking build system type... x86_64-apple-darwin18.7.0
    
    ...