LoginSignup
2
2

More than 5 years have passed since last update.

zipimport.ZipImportError: can't decompress data; zlib not availableの対処

Posted at

pyenvで最新版の3.7.0を入れようとしたところタイトルのエラーがでた

実行コマンド

pyenv install 3.7.0

エラー詳細

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

BUILD FAILED (OS X 10.13.5 using python-build 1.2.6)

Inspect or clean up the working tree at /var/folders/81/sn1mnk7s46j9l0r4gbb2q_6s076m6k/T/python-build.20180719181130.73197
Results logged to /var/folders/81/sn1mnk7s46j9l0r4gbb2q_6s076m6k/T/python-build.20180719181130.73197.log

Last 10 log lines:
  File "/private/var/folders/81/sn1mnk7s46j9l0r4gbb2q_6s076m6k/T/python-build.20180719181130.73197/Python-3.7.0/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/private/var/folders/81/sn1mnk7s46j9l0r4gbb2q_6s076m6k/T/python-build.20180719181130.73197/Python-3.7.0/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/81/sn1mnk7s46j9l0r4gbb2q_6s076m6k/T/python-build.20180719181130.73197/Python-3.7.0/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/81/sn1mnk7s46j9l0r4gbb2q_6s076m6k/T/python-build.20180719181130.73197/Python-3.7.0/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

解決策

xcode-select --install

完了してから、再インストールしたら成功。

3.7.0を入れた後に3.6.6を入れようとしたら同様のエラーが発生

解決策

$ brew info zlib

zlib: stable 1.2.11 (bottled) [keg-only]
General-purpose lossless data-compression library
https://zlib.net/
/usr/local/Cellar/zlib/1.2.11 (12 files, 373KB)
  Poured from bottle on 2019-01-16 at 16:52:44
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zlib.rb
==> Caveats
zlib is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

For compilers to find zlib you may need to set:
  export LDFLAGS="-L/usr/local/opt/zlib/lib"
  export CPPFLAGS="-I/usr/local/opt/zlib/include"

For pkg-config to find zlib you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"

==> Analytics
install: 9,036 (30 days), 29,291 (90 days), 74,561 (365 days)
install_on_request: 7,818 (30 days), 25,042 (90 days), 60,748 (365 days)
build_error: 0 (30 days)

表示されたexportを実行

それぞれの環境変数の設定を行った後、installすると成功した

$ export LDFLAGS="-L/usr/local/opt/zlib/lib"
$ export CPPFLAGS="-I/usr/local/opt/zlib/include"
$ export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"

Python3.6.6のインストール

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

参考

Install failed, "zlib not available" on macOS Mojave

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