CentOS7.4快速编译安装Python-3.6.3及pip
系统版本是CentOS Linux release 7.4.1708 (Core) 迷你版安装的,Python默认版本是2.7.5,升级到python3.6.3的步骤如下:
如果是要安装Python3.9等以上版本需要,需要升级ssh和ssl:
参考:
CentOS7快速升级OpenSSL到最新版
CentOS7快速升级OpenSSH到最新版本
1、升级安装基础工具包
yum install sqlite-devel sqlite vim wget unzip zip xz xz-devel tar tk tk-devel lrzsz openssl openssl-devel net-tools ntpdate vixie-cron crontabs sysstat bind-utils mysql-devel libffi libffi-devel -y
yum install gcc gcc-c++ gcc-g77 zlib zlib-devel zlib* readline* gcc* make cmake autoconf automake ncurses ncurses-devel bzip2 bzip2-devel gdbm gdbm-devel python-devel -y
yum groupinstall 'development tools' -y
yum install https://centos7.iuscommunity.org/ius-release.rpm
yum update -y
2、下载、编译、安装
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
mkdir /usr/local/python3
xz -d Python-3.6.3.tar.xz
tar xvf Python-3.6.3.tar
cd Python-3.6.3
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-ssl --enable-optimizations
#--prefix 安装目录,--enable-optimizations优化参数(LTO,PGO)性能有10%左右的提升,会增加编译时间
make
make install
3、做软连接、修改yum、libexec的python版本
mv /usr/bin/python /usr/bin/python_bak #备份
ln -s /usr/local/python3/bin/python3 /usr/bin/python #软连接
将/usr/bin/yum和/usr/libexec/urlgrabber-ext-down及/usr/bin/yum-config-manager中第一行的 #!/usr/bin/python 改为 #!/usr/bin/python2.7保存即可正常使用yum
4、添加环境变量:
echo 'export PATH=$PATH:/usr/local/python3/bin' >> /etc/profile
source /etc/profile
5、安装epel-release升级pip
yum install epel-release -y
yum install python-pip -y
pip install -U pip
至此python3.6.3安装完毕。
Tag标签:「python pip」更新时间:「2024-05-20 16:33:03」阅读次数:「713」