過去の日記

2020-02-25 [長年日記]

古いPythonをmacOS + Homebrew + pyenv環境でビルドしたい [Python]

古いPythonをpyenv installしようとすると

The Python ssl extension was not compiled. Missing the OpenSSL lib

みたいなエラーが出てビルドできません。

https://github.com/pyenv/pyenv/issues/950#issuecomment-575772777

I believe the issue here is that python <= 3.5.2 needs openssl 1.0. Homebrew removed openssl 1.0 recently (Homebrew/homebrew-core#46454). I suspect installing anything v3.5.3 or greater will work, but anything older than that won't compile with openssl 1.1.


とあります。
つまり、OpenSSL1.0が必要なのだけど、Homebrewでは1.1がインストールされていて、1.0はもうない。
pyenv install すると Homebewでインストールされている1.1を見つけてしまい、それを使おうとするのでエラーになってしまう。
ということです。

https://github.com/pyenv/pyenv/issues/950#issuecomment-576356578

What worked for me was: brew uninstall --ignore-dependencies openssl then installing python. In my case I was using asdf, but I think python will install its own version of openssl if you do that.


とある通りなので、例えば

brew uninstall --ignore-dependencies openssl
pyenv install 3.4.10
brew install openssl

などとすると解決します。
この場合pyenvが必要なOpenSSLをダウンロードしてビルドしてくれます。
.pyenv/versions/3.4.10/openssl みたいなところに展開してくれるので、システム全体への影響もなし。