centos7快速安装python3


拿到手一台云服务器安装centos7后,默认python版本为python2.7,pip命令不存在,如何快速安装pip及python3

python2.7安装pip

为python2.7安装pip工具。
centos7为python2.7安装pip
先安装setuptools后安装pip 或 yum -y install python-pip
sudo yum install python-setuptools
sudo easy_install pip

安装python3及pip3

yum search python36
配置好Python3.6和pip3
安装EPEL和IUS软件源
yum install epel-release -y
yum install https://centos7.iuscommunity.org/ius-release.rpm -y
安装Python3.6
yum install python36u -y
yum install python36u-devel.x86_64 -y
创建python3连接符
ln -s /bin/python3.6 /bin/python3
安装pip3
yum install python36u-pip -y
创建pip3链接符
ln -s /bin/pip3.6 /bin/pip3

python3一键安装脚本

bash install_python3.sh

#!/usr/bin/bash
PYTHON_VERSION=3.7.5
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget libffi-devel
cd /opt && wget http://npm.taobao.org/mirrors/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && tar -zxvf Python-${PYTHON_VERSION}.tgz
cd /opt/Python-${PYTHON_VERSION}
./configure
make&&make install
rm -rf /usr/bin/python3  && ln -s /usr/local/bin/python3  /usr/bin/python3
rm -rf /usr/bin/pip3  && ln -s /usr/local/bin/pip /usr/bin/pip3

rm -rf /opt/Python-${PYTHON_VERSION}*
if [ ! -d "/root/.pip" ]; then
  mkdir ~/.pip
fi
rm -rf ~/.pip/pip.conf && touch ~/.pip/pip.conf
echo "[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com" >> ~/.pip/pip.conf

`

多版本python共存

安装pyenv操作pyenv