LoginSignup
0
0

pyenvで「BUILD FAILED (OS X 14.2.1 using python-build 20180424)」でOpenSSLモジュールが見つからない時の対処法

Last updated at Posted at 2024-01-17

環境

OS:macOS 14.2.1
pyenv 2.3.35
shell: zsh

起こっていた問題

pyenvで python 3.11.4をインストールしようとしたら下記のようなエラーが発生

❯ pyenv install 3.11.4                                                                                                               ─╯
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.4.tar.xz...
-> https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz
Installing Python-3.11.4...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from homebrew
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/toyama/.pyenv/versions/3.11.4/lib/python3.11/ssl.py", line 100, 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 20180424)

どうやらopensslのモジュールが見つけられない模様

解決法

インストールはされているので環境変数を設定する

zshrc
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib $LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include $CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"

これでいけると思われたがまた同じエラーが発生
色々調べた結果OpenSSLの1.1を指定する必要がある模様

zshrc
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib $LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include $CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

成功しました

❯ pyenv install 3.11.4                                                                                                               ─╯
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.4.tar.xz...
-> https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz
Installing Python-3.11.4...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use ncurses from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.11.4 to /Users/toyama/.pyenv/versions/3.11.4
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0