みずきち日記

ひらすらプログラミング

pyenv install 中に BUILD FAILED してしまう

Python のバージョン管理に pyenv を使っています.

Jango を使ってみようと,新しく Python バージョンを入れようとしました.

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

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

Inspect or clean up the working tree at /var/folders/px/90g_3pjj7jndszmdtk9ybnqw0000gn/T/python-build.20190129040150.78545
Results logged to /var/folders/px/90g_3pjj7jndszmdtk9ybnqw0000gn/T/python-build.20190129040150.78545.log

Last 10 log lines:
  File "/private/var/folders/px/90g_3pjj7jndszmdtk9ybnqw0000gn/T/python-build.20190129040150.78545/Python-3.6.0/Lib/ensurepip/__main__.py", line 4, in <module>
    ensurepip._main()
  File "/private/var/folders/px/90g_3pjj7jndszmdtk9ybnqw0000gn/T/python-build.20190129040150.78545/Python-3.6.0/Lib/ensurepip/__init__.py", line 189, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/px/90g_3pjj7jndszmdtk9ybnqw0000gn/T/python-build.20190129040150.78545/Python-3.6.0/Lib/ensurepip/__init__.py", line 102, in bootstrap
    _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/px/90g_3pjj7jndszmdtk9ybnqw0000gn/T/python-build.20190129040150.78545/Python-3.6.0/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

なぜか怒られます.

すぐに xcode-select --install で治るらしいと知ったのですが,

僕の場合は再度試しても同じでした.

いろいろ調べてみると,こちら の issue に解決策が載っていました.

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

※ 現在 MAC OS Mojave を使っているので,たまたまバージョンが一緒だったので動きましたが,お使いの環境に合わせて変更したほうがいいと思います.

てことで,無事に Python3.6.0 が入り.

$ pyenv install 3.6.0
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.0.tar.xz...
-> https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
Installing Python-3.6.0...
python-build: use readline from homebrew
Installed Python-3.6.0 to /Users/fmzk/.pyenv/versions/3.6.0

django 用の仮想環境も作れました.

$ pyenv virtualenv 3.6.0 django3.6.0
Requirement already satisfied: setuptools in /Users/fmzk/.pyenv/versions/3.6.0/envs/django3.6.0/lib/python3.6/site-packages
Requirement already satisfied: pip in /Users/fmzk/.pyenv/versions/3.6.0/envs/django3.6.0/lib/python3.6/site-packages

作業用ディレクトリ配下で Python3.6.0 & 指定した仮想環境で実行できるように

$ pyenv local 3.6.0/envs/django3.6.0

とやっておしまい.

久々の更新でした(もっと頻度上げましょう)