天天看点

centos7自带python版本_Centos7安装指定版本的Python

本文主要介绍在Centos7系统上如果安装编译指的Python版本,本例安装Python-3.6.1

首先,为系统安装所需的依赖库,可根据具体使用情况安装,如:yum install -y gcc zlib zlib-devel openssl-devel bzip2-devel openssl-devel sqlite-devel ncurese-devel

下载源码包:wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz

解压安装:# xz -d Python-3.6.1.tar.xz

# tar -xvf Python-3.6.1.tar

# cd Python-3.6.1/

# ./configure --prefix=/usr/local/python3 --enable-optimizations

# make && make install

创建命令软链接:# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3

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

安装相应模板,根据需要安装,如:pip3 install pymysql

pip3 install requests

pip3 install PyQuery

如果出现如下提示:You are using pip version 9.0.1, however version 18.0 is available.You should consider upgrading via the 'pip install --upgrade pip' command.

表可pip版本过低,可执行命令升级:# pip3 install --upgrade pip