macOS High Sierra(10.13)でのERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?への対処

macOS High Sierra(10.13)でpyenvを使い、Python 3.5.3や2.7.14をインストールしようとすると成功したように見えて次のエラーがでて正しくインストールされない現象に遭遇。macOS High Sierra: ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? #993などを参考に正しくインストールする方法を探った際の記録。

インストール時のエラーメッセージ

$ pyenv install 3.6.3
Downloading Python-3.6.3.tar.xz...
-> https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
Installing Python-3.6.3...
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 (OS X 10.13 using python-build 20160602)

Inspect or clean up the working tree at /var/folders/yf/79cdmmgx74s6z0_9yf_tz1fw0000gq/T/python-build.20171022085825.57793
Results logged to /var/folders/yf/79cdmmgx74s6z0_9yf_tz1fw0000gq/T/python-build.20171022085825.57793.log

Last 10 log lines:
            upgrade) ensurepip="--upgrade" ;; \
            install|*) ensurepip="" ;; \
        esac; \
         ./python.exe -E -m ensurepip \
            $ensurepip --root=/ ; \
    fi
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0

最終行でSuccessfullyと出るのでうまくいっているように見えるが赤字で示す行の通りOpenSSlのライブラリが見つからないと出ている。

正しくインストールする操作手順

色々試した結果、次の操作でエラーを回避した。

  1. homebrewでHigh Sierra以前でインストールしたopensslパッケージを強制的にアンインストール
  2. homebrewで再度opensslパッケージをインストール
  3. openssl再インストール時に表示されたコマンドを実行
  4. bashの環境変数PATHを修正
  5. 再度pyenvコマンドでpythonのインストール

実行したコマンドなど

$ brew uninstall --ignore-dependencies --force openssl
$ brew install openssl
$ /usr/local/opt/openssl/bin/c_rehash

~/.bash_profile内の環境変数PATHの設定を変更

export PATH="/usr/local/opt/openssl/bin:$PATH"

~/.bash_profileの変更反映とインストール

$ source ~/.bash_profile
$ peen install 3.5.3
# 2.7.14では次のコマンドを実行
$ LDFLAGS="-L/usr/local/opt/openssl/lib" CPPFLAGS="-I/usr/local/opt/openssl/include" pyenv install 2.7.14

これでバージョン2と3の最新バージョンが利用できる。

実はHomebrewではバージョン2.7.14と3.6.3がインストールされている

コメントする

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください