centos7.* 安装 python3,pip3

centos7.* 安装 python3,pip3

yum安装方式

添加epel源

1
yum install epel-release

安装Python3.4

1
python34

安装pip3

1
2
yum install python34-setuptools
easy_install-3.4 pip

之后就可以使用pip3

1
pip3

源代码编译安装此方法兼容保留Python2共存

安装依赖环境

1
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

查看最新的Python版本

浏览器打开 https://www.python.org/ftp/python/ 查看最新的Python版本,标记为3.A.B

1
wget https://www.python.org/ftp/python/3.A.B/Python-3.A.B.tgz

创建Python3的目录

1
mkdir /usr/local/python3

解压下载文件并切换目录

1
2
3
tar -zxvf Python-3.A.B.tgz

cd Python-3.A.B

执行

1
2
./configure --prefix=/usr/local/python3
make && make install

创建Python3的软链接

1
ln -s /usr/local/python3/bin/python3 /usr/bin/python3

创建Pip3的软链接

1
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

测试命令 python3 和 pip3

1
2
python3
pip3