pyenv BUILD FAILED解决方法

今天被python2.x的中文问题弄的头痛,发现python3.x对中文支持很好,但是又担心某些包不支持python3的版本。遂使用pyenv来管理python。

操作系统:osx 10.11

首先我使用了homebrew安装了pyenv,这一步在网上看到会出错,然后如何如何解决,但是幸运的是我这里并没有什么卵错误。本以为可以顺利结束了,问题来了

问题:使用pyenv install 3.4.1时,下载之后出现了如下问题

Downloading Python-3.4.1.tgz...-https://yyuu.github.io/pythons/44a3c1ef1c7ca3e4fd25242af80ed72da941203cb4ed1a8c1b724d9078965dd8
Installing Python-3.4.1...

BUILD FAILED (OS X 10.9.5 using python-build 20150124)

Inspect or clean up the working tree at /var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726
Results logged to /var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726.log

Last 10 log lines:
  File "/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.1/Lib/ensurepip/__main__.py", line 4, in <module>
    ensurepip._main()
  File "/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.1/Lib/ensurepip/__init__.py", line 209, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.1/Lib/ensurepip/__init__.py", line 116, in bootstrap
    _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.1/Lib/ensurepip/__init__.py", line 40, in _run_pip
    import pip
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

解决方法:使用如下语句安装即可解决问题

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 3.4.1
  • 1
  • 2

原因:

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

至此安装新版本的python大功告成,可以使用pyenv versions查看安装结果。(此处星号应该在system上,小弟已经修改了python 的版本)

 system
* 3.4.1 (set by /usr/local/var/pyenv/version)
  • 1
  • 2
  • 3

另外,温馨提醒,在使用homebrew安装pyenv之后要安装homebrew的提示在.bash_profile中加入两句话,不知道和顺序有没有关系,我加反了之后就始终无法改变python的版本。

就是这两句,可以使用brew info pyenv 查看 
结果如下:

pyenv: stable 20160310, HEAD
Python version management
https://github.com/yyuu/pyenv
/usr/local/Cellar/pyenv/20160310 (473 files, 2.1M) *
  Built from source
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/pyenv.rb
==> Dependencies
Recommended: autoconf ✔, pkg-config ✔, openssl ✔, readline ✔
==> Options
--without-autoconf
    Build without autoconf support
--without-openssl
    Build without openssl support
--without-pkg-config
    Build without pkg-config support
--without-readline
    Build without readline support
--HEAD
    Install HEAD version
==> Caveats
To use Homebrew's directories rather than ~/.pyenv add to your profile:
  export PYENV_ROOT=/usr/local/var/pyenv

To enable shims and autocompletion add to your profile:
  if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

就是要加入如下两句:

To use Homebrew's directories rather than ~/.pyenv add to your profile:
  export PYENV_ROOT=/usr/local/var/pyenv

To enable shims and autocompletion add to your profile:
  if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

至此,使用pyenv global 3.4.1 即可成功切换python版本。

posted @ 2018-07-02 06:20  duxiao123  阅读(991)  评论(0编辑  收藏  举报