MacBook 上用 Pyenv 安装 Python 3.6.4 报错失败

环境

  • MacBook
    macOS High Sierra Version 10.13.4 (17E199)
    MacBook 上用 Pyenv 安装 Python 3.6.4 报错失败_第1张图片
    Screen Shot 2018-06-04 at 11.03.01 AM.png
  • pyenv
    pyenv1.2.2
    Screen Shot 2018-06-04 at 11.05.19 AM.png

遇到问题时的操作过程

  • 查看可用版本
$ pyenv install --list
Available versions:
  ... 省略 ... 
  3.6.0
  3.6-dev
  3.6.1
  3.6.2
  3.6.3
  3.6.4  <================ # 在这里
  ... 省略 ... 
  • 安装 version : 3.6.4 出错
$ pyenv install 3.6.4
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.4.tar.xz...
-> https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
Installing Python-3.6.4...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.13.4 using python-build 20160602)

Inspect or clean up the working tree at /var/folders/1_/7ctdn3wx7bj_6212hbdq8csh0000gn/T/python-build.20180604105334.6831
Results logged to /var/folders/1_/7ctdn3wx7bj_6212hbdq8csh0000gn/T/python-build.20180604105334.6831.log

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

再次挑战安装,成功!~

重新执行一次安装

$ pyenv install 3.6.4
python-build: use openssl from homebrew
python-build: use readline from homebrew
Installing Python-3.6.4...
python-build: use readline from homebrew
Installed Python-3.6.4 to /Users/starduliang/.pyenv/versions/3.6.4

再次确认安装成功

 ~  pyenv versions
* system (set by /Users/starduliang/.python-version)
  2.7.10
  3.5.0
  3.6.4 <================ #在这里
  anaconda3-4.3.1

参考 : https://qiita.com/maosanhioro/items/bf93540515d4ea75b222

你可能感兴趣的:(MacBook 上用 Pyenv 安装 Python 3.6.4 报错失败)