macOS Mojave: pyenvでPython 3.7.2インストールのトラブルメモ


前提


  • macOS Movave 10.14.2

  • Xcode CommandLine Tools



    • $ xcode-select --install



  • Homebrew 2.0.2

  • pyenv 1.2.9


やりたいこと: Python本体のインストール

$ pyenv install 3.7.2


結論


1. もしHomebrewの binutils をインストールしていたら、削除しておく



  • brew install binutils したときに次のように言われる:


    • because Apple provides the same tools and binutils is poorly supported on macOS.



  • Homebrew版のbinutilsは削除して、Appleのbinutilsを使用する。

$ brew uninstall binutils


2. zlibを手動でインストールする

参考: [MacOS Mojave]pyenvでpythonのインストールがzlibエラーで失敗した時の対応 - Qiita


xcode-selectの最新バージョン(2354)にMojave用のmacOS SDK headerがデフォルトで入っていないのが原因のようです。

マニュアルで以下をインストールする必要ある:


sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

以上でインストールできました。


エラーログ

上記 1. / 2. に対応します。


1. ld: symbol(s) not found for architecture x86_64

$ pyenv install 3.7.2

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.2.tar.xz...
-> https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
Installing Python-3.7.2...
python-build: use readline from homebrew

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

Inspect or clean up the working tree at /var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173000.59889
Results logged to /var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173000.59889.log

Last 10 log lines:
"__Py_InitializeFromConfig", referenced from:
_test_init_from_config in _testembed.o
_test_init_dev_mode in _testembed.o
_test_init_isolated in _testembed.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [Programs/_testembed] Error 1
make: *** Waiting for unfinished jobs....
make: *** [python.exe] Error 1


2. zipimport.ZipImportError: can't decompress data; zlib not available

$ pyenv install 3.7.2

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.2.tar.xz...
-> https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
Installing Python-3.7.2...
python-build: use readline from homebrew

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

Inspect or clean up the working tree at /var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173739.79362
Results logged to /var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173739.79362.log

Last 10 log lines:
File "/private/var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173739.79362/Python-3.7.2/Lib/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/private/var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173739.79362/Python-3.7.2/Lib/ensurepip/__init__.py", line 204, in _main
default_pip=args.default_pip,
File "/private/var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173739.79362/Python-3.7.2/Lib/ensurepip/__init__.py", line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/private/var/folders/hw/pnp2g_hx2zj3_4m40lyyqq8w0000gn/T/python-build.20190221173739.79362/Python-3.7.2/Lib/ensurepip/__init__.py", line 27, in _run_pip
import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1