LoginSignup
0
2

More than 3 years have passed since last update.

【macOS Big Sur】pyenvでpythonインストールするまでに詰まった話

Posted at

開発環境

・Macbook Air Big Sur 11.1
・pyenv 1.2.26
・xcode-select version 2384
・XCode 12.4

やりたいこと

pyenvでpython3.7.3をインストールしたい

発生したこと

$ pyenv install 3.7.3

だめだった・・・

BUILD FAILED (OS X 11.0.1 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20201120091233.71993
Results logged to /tmp/python-build.20201120091233.71993.log

Last 10 log lines:
./Modules/posixmodule.c:8210:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ret = sendfile(in, out, offset, &sbytes, &sf, flags);
^
./Modules/posixmodule.c:10432:5: warning: code will never be executed [-Wunreachable-code]
Py_FatalError("abort() called from Python code didn't abort!");
^~~~~~~~~~~~~
1 warning and 1 error generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated`

解決手順

zlib bzip2を再インストール

$ brew reinstall zlib bzip2

zshrcファイルにパスを追加

$ vi ~/.zshrc

ここから↓
export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="/usr/local/bin:$PATH"

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/bzip2/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include"
ここまで書く↑

インストールしたいバージョンを自由にいれて、叩く

$ CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.7.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

別のエラー・・・・・・

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

openSSLをインストール

$ brew install openssl

zshrcファイルにパスを追加

$ vi ~/.zshrc

ここから↓
export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"
ここまで書く↑

もう一度チャレンジ・・・!

$ CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.7.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

いけた!

Installed Python-3.7.3 to /Users/ワシの名前/.pyenv/versions/3.7.3

 $ pyenv versions
    system
    * 3.7.3 (set by /Users/tomomitakei/.pyenv/version)

参考文献

0
2
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
2