Open6
pyenvでのpythonインストールエラー(Missing the OpenSSL lib?)

pyenvでPython2をインストールしようとすると、OpenSSLがインストールされていないというエラーが発生
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems
BUILD FAILED (Ubuntu 20.04 using python-build 2.4.10)

エラーメッセージ内のURLを開くと、OpenSSLに関しては次の項目が該当する

手順に沿って順番に確認していく。
- First, check
if you actually have OpenSSL and its headers installed (and for the right architecture and ecosystem if there are more than one at your machine)
Ubuntu: sudo apt install libssl-dev
Fedora: sudo dnf install openssl-devel
if the problem is resolved by upgrading Pyenv to the latest release and to the head version
最初のOpenSSLに関しては問題なし。
$ sudo apt install libssl-dev
libssl-dev is already the newest version (1.1.1f-1ubuntu2.23).
Pyenvも最新バージョンがインストール済
$ pyenv -v
pyenv 2.4.10

次はOpenSSLが通常と異なるパスにインストールされている場合の対策。
- OpenSSL is installed to an uncommon location.
Pass the location of its headers and libraries explicitly: (the openssl folder can be found by running openssl version -d)
CPPFLAGS="-I<openssl install prefix>/include"
LDFLAGS="-L<openssl install prefix>/lib"
pyenv install -v <python version>
まず、OpenSSLのフォルダーを表示する
$ openssl version -d
OPENSSLDIR: "/home/linuxbrew/.linuxbrew/etc/openssl@1.1"
オプションを指定してPythonインストールを試したが、変わらずエラー
$ CPPFLAGS="-I/home/linuxbrew/.linuxbrew/etc/openssl@1.1/include" \
LDFLAGS="-L/home/linuxbrew/.linuxbrew/etc/openssl@1.1/lib" \
pyenv install -v 2.7.2
(中略)
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems
BUILD FAILED (Ubuntu 20.04 using python-build 2.4.10)

次の項目を確認すると、OpenSSLとPythonのバージョン不整合が原因?
- Your OpenSSL version is incompatible with the Python version you're trying to install
Old Python versions (for CPython, <3.5.3 and <2.7.13) require OpenSSL 1.0 while newer systems provide 1.1, and vice versa.
Note that OpenSSL 1.0 is EOL and by now practically unusable on the Internet due to using obsolete standards.
Install the right OpenSSL version, and point the build to its location as per above if needed.

単にPython 2系をインストールしたいだけで、詳細なバージョンはどれでもいい。
2系の最新である2.7.18
のインストールをためすと、あっさり成功した
$ pyenv install 2.7.18
...
Installed Python-2.7.18 to /home/.../.pyenv/versions/2.7.18