Pyenv 安装Python 3.7

安装环境

Ubuntu 14.x

安装Pyenv

1
2
3
4
5
6
7
8
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
# 安装后会提示环境写入环境
vim ~/.bashrc
#写入:
export PATH="/root/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
source ~/.bashrc

Pyenv 常用命令

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
27
28
29
30
31
32
33
34
35
36
37
38
root@iZ9***jk65Z:/etc# pyenv commands
activate
commands
completions
deactivate
doctor
exec
global
help
hooks
init
install #安装指定软件,例如 pyenv install 3.5.2|install --list 查看python可用版本資源
installer
local #切换到指定版本只对当前目录有效,例如pyenv local 3.5.2
#pyenv local 2.7.8 3.5.1 同時設置多個當前版本
offline-installer
prefix
rehash #刷新版本包(每次安裝新版本時,執行一次)
root
shell
shims
uninstall #卸载python或虚拟环境
update
version
--version
version-file
version-file-read
version-file-write
version-name
version-origin
versions #所有python 版本
virtualenv #使用虚拟环境,例如pyenv virtualenv 3.5.2 test
virtualenv-delete
virtualenv-init
virtualenv-prefix
virtualenvs
whence
which

其他命令详解参考官方文档

安装编译3.7.1

1
2
3
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev
  • The Python ssl extension was not compiled. Missing the OpenSSL lib?
    python3.7为了安全性考虑,要求使用openssl 1.0.2之后的版本。但是阿里云的版本还是OpenSSL 1.0.1e-fips,手动升级

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    wget http://www.openssl.org/source/openssl-1.0.2j.tar.gz
    tar -xzf openssl-1.0.2j.tar.gz
    cd openssl-1.0.2j
    ./config shared zlib
    ./config -t
    make
    make install
    #编辑etc/ld.so.conf文件,添加:
    /usr/local/ssl/lib
    #查看
    ldconfig -v
  • 再次安装就成功了

    1
    LD_RUN_PATH="/usr/local/ssl/lib" LDFLAGS="-L/usr/local/ssl/lib" CPPFLAGS="-I/usr/local/ssl/include" CFLAGS="-I/usr/local/ssl/include" CONFIGURE_OPTS="--with-openssl=/usr/local/ssl" pyenv install 3.7.1