pyenv:构建失败(OS X 10.15.7 使用 python-build 20180424)

pyenv: BUILD FAILED (OS X 10.15.7 using python-build 20180424)

我刚刚在 macOS Catalina 上安装了 pyenv,我收到以下命令的错误消息 pyenv doctor:

Cloning /Users/joel.rontynen/.pyenv/plugins/pyenv-doctor/bin/.....
Installing python-pyenv-doctor...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

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

Inspect or clean up the working tree at /var/folders/tl/_2700jnn5vj0q5ryygn4c4ww0000gp/T/python-build.20201014132428.46509
Results logged to /var/folders/tl/_2700jnn5vj0q5ryygn4c4ww0000gp/T/python-build.20201014132428.46509.log

Last 10 log lines:
checking readline/readline.h, presence... no
checking for readline/readline.h,... no
checking readline/rlconf.h usability... yes
checking readline/rlconf.h presence... yes
checking for readline/rlconf.h... yes
checking for SSL_library_init in -lssl... no
configure: WARNING: OpenSSL <1.1 not installed. Checking v1.1 or beyond...
checking for OPENSSL_init_ssl in -lssl... no
configure: error: OpenSSL is not installed.
make: *** No targets specified and no makefile found.  Stop.
Problem(s) detected while checking system.

See https://github.com/pyenv/pyenv/wiki/Common-build-problems for known solutions.

日志文件如下所示:

/var/folders/tl/_2700jnn5vj0q5ryygn4c4ww0000gp/T/python-build.20201021121358.92440 ~
Cloning into 'python-pyenv-doctor'...
warning: --depth is ignored in local clones; use file:// instead.
done.
/var/folders/tl/_2700jnn5vj0q5ryygn4c4ww0000gp/T/python-build.20201021121358.92440/python-pyenv-doctor /var/folders/tl/_2700jnn5vj0q5ryygn4c4ww0000gp/T/python-build.20201021121358.92440 ~
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether clang accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking for rl_gnu_readline_p in -lreadline... yes
checking how to run the C preprocessor... clang -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking readline/readline.h, usability... no
checking readline/readline.h, presence... no
checking for readline/readline.h,... no
checking readline/rlconf.h usability... yes
checking readline/rlconf.h presence... yes
checking for readline/rlconf.h... yes
checking for SSL_library_init in -lssl... no
configure: WARNING: OpenSSL <1.1 not installed. Checking v1.1 or beyond...
checking for OPENSSL_init_ssl in -lssl... no
configure: error: OpenSSL is not installed.
make: *** No targets specified and no makefile found.  Stop.

我使用 Homebrew 安装了 pyenv 和 pyenv-virtualenv,并通过克隆 GitHub 存储库安装了 update 和 doctor 插件。命令 brew list 给出以下输出:

fig             pyenv-virtualenv    xz
openssl@1.1     pyenv               readline

我的 .zshrc 文件如下所示:

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

和 .zshenv 文件如下:

eval "$(pyenv virtualenv-init -)"

我不确定还有哪些相关信息,所以您可以在评论中询问更多信息。

问题是与 Homebrew 一起安装的 OpenSSL,但它“没有符号链接到 /usr/local,因为 macOS 提供了 LibreSSL。”我通过 运行 命令 brew info openssl 了解到这一点,它说

openssl@1.1: stable 1.1.1h (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/usr/local/Cellar/openssl@1.1/1.1.1h (8,067 files, 18.5MB)
  Poured from bottle on 2020-10-14 at 12:44:32
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb
License: OpenSSL
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

可以在上面消息中的“==> Caveats”行下找到修复程序。我将 export LDFLAGS 和 CPPFLAGS 行添加到我的 ~/.zshrc 文件中,pyenv doctor 命令不再给出任何错误。