如何在CentOS 7 中基于OpenSSL 1.0 搭建Python 3.0 环境

1、下载

通过https://www.python.org/ftp/python/下载Python安装包,这里下载Python-3.10.9.tgz;

2、上传

借助MobaXterm等工具将Python安装包上传至/opt目录;

3、解压

将JDK压缩文件解压至/opt目录:tar -xvf /opt/Python-3.10.9.tgz -C /opt

4、删除

删除压缩文件:rm -f /opt/Python-3.10.9.tgz

5、依赖

原因

①、Python-3.10.9.tgz只是Python源码,需要先编译,才能安装,所以需要安装gcc;

②、编译安装Python期间需要诸如ncurses-devel和sqlite-devel等环境,否则提示如下信息:

如何在CentOS 7 中基于OpenSSL 1.0 搭建Python 3.0 环境_第1张图片

安装

# yum -y install gcc ncurses-devel sqlite-devel readline-devel zlib-devel libffi-devel bzip2-devel tk-devel gdbm-devel xz-devel
6、OpenSSL

原因

安装Python 3 前必须先安装OpenSSL,否则编译安装Python3时提示如下信息:

在这里插入图片描述

安装

# yum -y install epel-release
# yum -y install openssl-devel openssl11 openssl11-devel

# 设置最新openssl库编译环境
# export CFLAGS=$(pkg-config --cflags openssl11)
# export LDFLAGS=$(pkg-config --libs openssl11)

注意:

必须先执行yum -y install epel-release,再执行yum -y install openssl11-devel,两条yum命令不要合起来一起执行,否则执行export命令时提示No package ‘openssl11’ found错误。

7、安装
# cd /opt/Python-3.10.9
# ./configure --prefix=/usr/local/python-3.10.9/
# make && make install

说明:–prefix 指定软件安装路径

8、环境
# tee >> /etc/profile << EOF
export PATH=/usr/local/python-3.10.9/bin:$PATH
EOF
# source /etc/profile
9、检查
[root@localhost Python-3.10.9]# python3 -V
Python 3.10.9
[root@localhost Python-3.10.9]# pip3 install pymysql -i https://mirrors.aliyun.com/pypi/simple/
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting pymysql
  Downloading https://mirrors.aliyun.com/pypi/packages/e5/30/20467e39523d0cfc2b6227902d3687a16364307260c75e6a1cb4422b0c62/PyMySQL-1.1.0-py3-none-any.whl (44 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.8/44.8 kB 298.5 kB/s eta 0:00:00
Installing collected packages: pymysql
Successfully installed pymysql-1.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip available: 22.3.1 -> 23.3.2
[notice] To update, run: pip3 install --upgrade pip
[root@localhost Python-3.10.9]#

你可能感兴趣的:(Python,Linux,centos,python,linux)