pyenv进行python版本本地安装

来源:互联网 发布:手机密室逃脱推荐 知乎 编辑:程序博客网 时间:2024/06/05 19:29

转载地址:http://blog.csdn.net/windeal3203/article/details/53413479

pyenv 是一个针对Python的多版本管理工具。使用pyenv可以很轻松的在一个系统上使用不同版本的python,并实现轻松的切换。 关于pyenv的更多介绍可以参考:https://github.com/yyuu/pyenv

pyenv install 命令用于在系统上安装python, 比如pyenv install 3.5.0 则可以帮助我们安装python 3.5.0.
然而,由于墙等原因, pyenv install 可能下载速度非常慢,甚至下载失败。本文主要介绍pyenv如何使用本地的python安装包,安装python。

本地安装,首先需要下载安装包,如Python-3.5.0.tar.xz。
pyenv并没有提供使用本地包安装python的命令。所以无法直接使用命令安装。

我们要了解pyenv的安装原理, 其实它是利用了python-build工具,从python官网下载python包,然后安装。

我的pyenv路径是:/usr/opt/pyenv/ 对应的python-build路径就为/usr/opt/pyenv/plugins/python-build/share/python-build.

而在/usr/opt/pyenv/plugins/python-build/share/python-build (注意路径比python-build多了两层)中有各种python版本的安装指令, 如3.5.2 版本:

windeal@ubuntu:python-build$ cat 3.5.0#require_gccinstall_package "openssl-1.0.2g" "https://www.openssl.org/source/openssl-1.0.2g.tar.gz#b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33" mac_openssl --if has_broken_mac_openssl install_package "readline-6.3" "https://ftpmirror.gnu.org/readline/readline6.3.tar.gz#56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43" standard --if has_broken_mac_readlineif has_tar_xz_support; then install_package "Python-3.5.0" "https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz#d6d7aa1634a5eeeca6ed4fca266982a04f84bd8f3945a9179e20b24ad2e2be91" ldflags_dirs standard verify_py35 ensurepipelse  install_package "Python-3.5.0" "https://www.python.org/ftp/python/3.5./Python3.5.0.tgz#584e3d5a02692ca52fce505e68ecd77248a6f2c99adf9db144a39087336b0fe0" ldflags_dirs standard verify_py35 ensurepipfiwindeal@ubuntu:python-build$ 

其中在install_package “Python-3.5.0” … 这一行指定了python3.5.0的获取方式,我们将其修改为:

windeal@ubuntu:python-build$ cat 3.5.0#require_gccinstall_package "openssl-1.0.2g" "https://www.openssl.org/source/openssl-1.0.2g.tar.gz#b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33" mac_openssl --if has_broken_mac_opensslinstall_package "readline-6.3" "https://ftpmirror.gnu.org/readline/readline-6.3.tar.gz#56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43" standard --if has_broken_mac_readlineif has_tar_xz_support; then#  install_package "Python-3.5.0" "https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz#d6d7aa1634a5eeeca6ed4fca266982a04f84bd8f3945a9179e20b24ad2e2be91" ldflags_dirs standard verify_py35 ensurepip  install_package "Python-3.5.0" "/usr/opt/pyenv/cache/Python-3.5.0.tar.xz" ldflags_dirs standard verify_py35 ensurepipelse  install_package "Python-3.5.0" "https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz#584e3d5a02692ca52fce505e68ecd77248a6f2c99adf9db144a39087336b0fe0" ldflags_dirs standard verify_py35 ensurepipfiwindeal@ubuntu:python-build$ 

其中/usr/opt/pyenv/cache/ 是我们存放本地安装包的路径。 (可能不存在需要自己创建)。

然后执行pyenv install 3.5.0 即可。

注意点:
本地安装需要一些依赖库,否则可能会安装失败。
可以根据报错信息修改。

0 0