pyenv,是用来管理电脑不同版本的python的一个管理工具,切换不同版本不会影响到系统自带的python。
pyenv,是一个开源软件,具体可以猛戳这里:https://github.com/yyuu/pyenv
安装就不说了,可以看项目使用说明,我说说我遇到的问题。
我按照说明做,当我执行:
$pyenv install3.4.2
pyenv安装信息如下
Downloading Python-3.4.2.tgz...-> https://yyuu.github.io/pythons/44a3c1ef1c7ca3e4fd25242af80ed72da941203cb4ed1a8c1b724d9078965dd8error: failed to download Python-3.4.2.tgz-> https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgzInstalling Python-3.4.2...ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?Please consult to the Wiki page to fix the problem.https://github.com/yyuu/pyenv/wiki/Common-build-problemsBUILD FAILED (OS X10.9.5using python-build20150124)Inspect or clean up the working tree at /var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127145029.76064Results logged to /var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127145029.76064.logLast10loglines:(cd/Users/karonchen/.pyenv/versions/3.4.2/share/man/man1; ln-spython3.4.1python3.1)iftest"xupgrade"!="xno";then\caseupgradein\ upgrade) ensurepip="--upgrade";; \ install|*) ensurepip="";; \esac; \ ./python.exe -E -m ensurepip \$ensurepip--root=/ ; \fiIgnoring ensurepip failure: pip1.5.6requires SSL/TLS
原因:
ERROR:The Python ssl extension was not compiled. Missing the OpenSSL lib?
所以,执行下面的代码可以解决这个问题:
CFLAGS="-I$(brew --prefix openssl)/include"\LDFLAGS="-L$(brew --prefix openssl)/lib"\pyenv install3.4.2
详情可以看着里:https://github.com/yyuu/pyenv/issues/22
pyenv安装反馈如下:
Downloading Python-3.4.2.tgz...->https://yyuu.github.io/pythons/44a3c1ef1c7ca3e4fd25242af80ed72da941203cb4ed1a8c1b724d9078965dd8Installing Python-3.4.2...BUILD FAILED (OS X10.9.5 using python-build20150124)Inspectorclean up the working tree at /var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726Results logged to /var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726.logLast10loglines: File"/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.2/Lib/ensurepip/__main__.py", line4,in ensurepip._main() File"/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.2/Lib/ensurepip/__init__.py", line209,in_main default_pip=args.default_pip, File"/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.2/Lib/ensurepip/__init__.py", line116,inbootstrap _run_pip(args + [p[0]forpin_PROJECTS], additional_paths) File"/private/var/folders/zf/1b6kcyd53hg0crv65j108_7m0000gn/T/python-build.20150127150918.87726/Python-3.4.2/Lib/ensurepip/__init__.py", line40,in_run_pipimportpipzipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
原因:
zipimport.ZipImportError:can't decompress data; zlib not available
执行下面的代码即可解决这个问题:
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include"pyenv install -v3.4.2
详情可以看着里:https://github.com/yyuu/pyenv/issues/25
以为这样就搞定了。。。可是:
当我在shell中输入
pyenv local3.4.2#设置机子使用的python为3.4.2版本$python --version$2.7.8
发现python还是之前的版本,这又是哪里出问题。
查了半天,发现是shell configuration没配置。具体可以参考这里:https://github.com/yyuu/pyenv/issues/228
需要在.bash_profile的最下面加入:
if whichpyenv > /dev/null;theneval"$(pyenv init -)";fi
and it worked!!