🐍

asdfでPythonがインストールできない(openssl関連のエラー)

2024/03/29に公開

Mac(OSはYosemite)でのRuntimeのバージョン管理にasdfを利用しています。Pythonをインストールする際に、特定のバージョンをインストールできないケースに遭遇したため、エラーの内容を解決した際のコマンドを記載します。

解決には、下記のIssueを参考にしました。

https://github.com/pyenv/pyenv/issues/993

asdf install python 3.10.10 ⇛ Error

初めにインストールを試みた際のエラーは、以下の通り。

asdf install python 3.10.10
python-build 3.10.10 /Users/yuki/.asdf/installs/python/3.10.10
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.10.10.tar.xz...
-> https://www.python.org/ftp/python/3.10.10/Python-3.10.10.tar.xz
Installing Python-3.10.10...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use ncurses from homebrew
python-build: use zlib from homebrew
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/yuki/.asdf/installs/python/3.10.10/lib/python3.10/ssl.py", line 99, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
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 14.2.1 using python-build 2.3.36-21-g7e550e31)

Inspect or clean up the working tree at /var/folders/nm/bzcpbrrx7y7b0b7hjylbvsd00000gn/T/python-build.20240329092958.92493
Results logged to /var/folders/nm/bzcpbrrx7y7b0b7hjylbvsd00000gn/T/python-build.20240329092958.92493.log

Last 10 log lines:
		DYLD_LIBRARY_PATH=/var/folders/nm/bzcpbrrx7y7b0b7hjylbvsd00000gn/T/python-build.20240329092958.92493/Python-3.10.10 ./python.exe -E -m ensurepip \
			$ensurepip --root=/ ; \
	fi
Looking in links: /var/folders/nm/bzcpbrrx7y7b0b7hjylbvsd00000gn/T/tmpk9towwzd
Processing /private/var/folders/nm/bzcpbrrx7y7b0b7hjylbvsd00000gn/T/tmpk9towwzd/setuptools-65.5.0-py3-none-any.whl
Processing /private/var/folders/nm/bzcpbrrx7y7b0b7hjylbvsd00000gn/T/tmpk9towwzd/pip-22.3.1-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: The scripts pip3 and pip3.10 are installed in '/Users/yuki/.asdf/installs/python/3.10.10/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.3.1 setuptools-65.5.0

解決策

解決した際の流れは以下の通り。

  • 現在利用しているopensslを一度アンインストール'
  • openssl@1.1をインストール
  • コンパイルのオプションに新たにインストールしたopensslのディレクトリを指定して、Pythonをインストール
brew uninstall --ignore-dependencies openssl
brew install openssl@1.1
CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" asdf install python 3.10.10

詳しくは下記を参照してください。

https://github.com/pyenv/pyenv/issues/993

Discussion