はじめに
pyenv + Python 3.4.3を構築するにあたって半日くらい費やしてしまったので、その備忘録です。
前提
- macOS Catalina 10.15.3
- Homebrew 2.2.10
- fish 3.1.0
- pyenv 1.2.16
pyenv install 3.8.1
pyenv global 3.8.1
は成功。
Python 3.4.3のインストール
同様にインストールを試みるもエラー発生。
pyenv install 3.4.3
↓
〜〜略〜〜
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
〜〜略〜〜
失敗: OpenSSLに関するコンパイルオプションの指定
公式Wiki1によると、「コンパイルオプションを指定すると良い」とのことだが、同様エラーにより撃沈。
If you have homebrew openssl and pyenv installed, you may need to tell the compiler where the openssl package is located:
試したコマンド(※fish用です。)
set -gx CPPFLAGS "-I/usr/local/opt/openssl/include"
set -gx LDFLAGS "-L/usr/local/opt/openssl/lib"
pyenv install 3.4.3
↓
〜〜略〜〜
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
〜〜略〜〜
成功: HomebrewからのOpenSSLパッケージの削除
同公式Wiki1によると、「(Ubuntuでは)OpenSSLのバージョン変更により解決するかも?」とのこと。
If you're having trouble to get it to compile older python versions(<3.5) even after installing the recommended packages on ubuntu, changing the openssl lib might help:
そこで、とりあえずHomebrewに入っているOpenSSLをアンインストールしてみた。ただし、同パッケージはpyenvが依存関係にあるため、--ignore-dependencies
オプションを指定。
brew uninstall --ignore-dependencies openssl@1.1
pyenv install 3.4.3
その後、ログを眺めていると冒頭でPython 3.4.3のインストールの前にOpenSSL 1.0.2kをビルドし始めて成功の予感が。
↓
Downloading openssl-1.0.2k.tar.gz...
-> https://pyenv.github.io/pythons/6b3977c61f2aedf0f96367dcfb5c6e578cf37e7b8d913b4ecb6643c3cb88d8c0
Installing openssl-1.0.2k...
〜〜略〜〜
Installed Python-3.4.3 to /Users/yaumu3/.pyenv/versions/3.4.3
無事成功です。
後片付け
Python 3.4.3インストール時にインストールされたOpenSSLを削除し、HomebrewにOpenSSLを再インストールする。
rm -rf /usr/local/opt/openssl
brew reinstall openssl@1.1
さいごに
- HomebrewからOpenSSLのアンインストール
- 古いバージョンのOpenSSLをHomebrewにインストール2
- PATHを通す
- コンパイルオプションを指定して
pyenv install 3.4.3
でも成功しますが、この方法が一番シンプルだと思います。