Python3安装 - 同步解决pip无法升级与使用的问题

准备

依赖工具

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

安装成功,提示如下

Python3安装 - 同步解决pip无法升级与使用的问题_第1张图片

安装后配置与校验

软链

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

你可能感兴趣的:(python基础,pip,python,开发语言)