Python3安装配置 for centos
2022-02-13 本文已影响0人
卡门001
一、准备
- 依赖工具
yum -y install zlib-devel bzip2-devel openssl-devel
yum -y install ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel xz-devel
yum -y install wget
- 编译工具
yum install -y gcc #编译器
yum install libffi-devel -y
二、openssl安装
cd /opt
find /etc/ -name openssl.cnf -printf "%h\n"
--
/etc/pki/tls
# 3.x的版本在centos 8下安装不兼容
curl -O https://www.openssl.org/source/openssl-1.1.1m.tar.gz
tar zxvf penssl-1.1.1m.tar.gz
cd openssl-1.1.1m
./config --prefix=/usr/local/custom-openssl --libdir=lib --openssldir=/etc/pki/tls
make -j1 depend
make -j8 && make install_sw
popd
四、下载安装python3
- 创建安装路径
mkdir -p /usr/local/python3
- 下载程序并解压
cd /opt
wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tar.xz
tar xvf Python-3.10.2.tar.xz
cd Python-3.10.2
- 编译安装
./configure -C --with-openssl=/usr/local/custom-openssl \
--with-openssl-rpath=auto --prefix=/usr/local/python3
make -j8
make altinstall
安装成功,提示如下
image.png
五、安装后配置与校验
- 软链
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
- 加入环境变量
vim /etc/profile
---
export PATH=$PATH:/usr/local/python3/bin
--
# 生效
source /etc/profile
六、检查版本
python3 -V
pip3 -V