Skip to content

Instantly share code, notes, and snippets.

@linw1995
Last active March 1, 2019 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linw1995/b8023f97b8913e5debe99aedbccb3a2a to your computer and use it in GitHub Desktop.
Save linw1995/b8023f97b8913e5debe99aedbccb3a2a to your computer and use it in GitHub Desktop.
安装 Python 3.7

在 Centos 6.8 中安装 Python 3.7

安装依赖

yum install -y \
  zlib \
  zlib-devel \
  sqlite-devel \
  bzip2-devel \
  libffi \
  libffi-devel \
  uuid \
  uuid-devel \
  ncurses-devel \
  readline-devel \
  tk-devel \
  gcc \
  make \
  perl

编译 openssl 1.0.2

Python3.7 需要 openssl 1.0.2 以上的版本

wget http://www.openssl.org/source/openssl-1.0.2j.tar.gz
tar -xzvf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j
openssl_dir=/usr/local/openssl/openssl-1.0.2j
./config \
  shared \
  zlib-dynamic \
  --prefix=$openssl_dir
make && make install

源码下载

首先在 python ftp 上下载最新 3.7 源码

wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar -zxvf Python-3.7.2.tgz
cd Python-3.7.2

编译 Python 3.7

python_dir=/usr/local/python/python3.7
openssl_dir=/usr/local/openssl/openssl-1.0.2j
./configure \
  --prefix=$python_dir \
  --enable-shared \
  LDFLAGS="-Wl,--rpath=$python_dir/lib:$openssl_dir/lib" \
  --with-openssl=$openssl_dir \
  --with-ensurepip=yes
make && make install
ln -s $python_dir/bin/python3.7 /usr/bin/python3.7
ln -s $python_dir/bin/python3.7-config /usr/bin/python3.7-config
ln -s $python_dir/bin/python3.7m /usr/bin/python3.7m
ln -s $python_dir/bin/python3.7m-config /usr/bin/python3.7m-config

在 Centos 7 中安装 Python 3.7

安装依赖

yum install -y \
  zlib \
  zlib-devel \
  sqlite-devel \
  bzip2-devel \
  libffi \
  libffi-devel \
  uuid \
  uuid-devel \
  ncurses-devel \
  readline-devel \
  tk-devel \
  openssl-devel \
  gcc \
  make

源码下载

首先在 python ftp 上下载最新 3.7 源码

wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar -zxvf Python-3.7.2.tgz
cd Python-3.7.2

编译 Python 3.7

python_dir=/usr/local/python/python3.7
./configure \
  --prefix=$python_dir \
  --enable-shared \
  LDFLAGS="-Wl,--rpath=$python_dir/lib" \
  --with-ensurepip=yes
make && make install
ln -s $python_dir/bin/python3.7 /usr/bin/python3.7
ln -s $python_dir/bin/python3.7-config /usr/bin/python3.7-config
ln -s $python_dir/bin/python3.7m /usr/bin/python3.7m
ln -s $python_dir/bin/python3.7m-config /usr/bin/python3.7m-config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment