4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macOS Mojaveでpyenvを使ったPythonのインストール時に出るZipImportErrorの回避方法

Posted at

はじめに

macOS Mojaveでpyenv経由でPythonをインストールしようとすると次のようなZipImportErrorが発生します。

$ 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.3 using python-build 1.2.9-19-g7d02b246)

Inspect or clean up the working tree at /var/folders/zd/wbvzn4ls3_xbtv033b0mp3hw0000gn/T/python-build.20190322153042.29836
Results logged to /var/folders/zd/wbvzn4ls3_xbtv033b0mp3hw0000gn/T/python-build.20190322153042.29836.log

Last 10 log lines:
  File "/private/var/folders/zd/wbvzn4ls3_xbtv033b0mp3hw0000gn/T/python-build.20190322153042.29836/Python-3.7.2/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/private/var/folders/zd/wbvzn4ls3_xbtv033b0mp3hw0000gn/T/python-build.20190322153042.29836/Python-3.7.2/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/zd/wbvzn4ls3_xbtv033b0mp3hw0000gn/T/python-build.20190322153042.29836/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/zd/wbvzn4ls3_xbtv033b0mp3hw0000gn/T/python-build.20190322153042.29836/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

解決方法

解決策としてmacOS SDK headersを/にインストールする方法が載っているサイトが多いのですが、そのインストールの手順は不要です。

既にヘッダーファイルは存在するため、CFLAGSにmacOS SDK headersのパスを渡してあげればよいです。

$ CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.7.2

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?