1、centos7默认支持的Python3版本为3.6,使用PyInstaller打包需要用到3.8的版本,需要使用scl来安装高版本的Python
SCL(Software Collections)可以让你在同一个操作系统上安装和使用多个版本的软件,而不会影响整个系统的安装包。SCL为社区的以下需求而设计:创建和使用软件集合生产系统、概念验证系统、开发测试平台。SCL目前已经支持Fedora和RHEL(衍生版本如CentOS也包含在内)。
2、配置scl
yum -y install centos-release-scl-rh centos-release-scl
3、安装Python3.8
yum install rh-python38
--设置环境变量
cat << EOF >/etc/profile.d/python38.sh
# create new
source /opt/rh/rh-python38/enable
export X_SCLS="`scl enable rh-python38 'echo $X_SCLS'`"
EOF
--source环境变量
source /etc/profile.d/python38.sh
--设置pip数据源
mkdir ~/.pip
cat << EOF > ~/.pip/pip.conf
[global]
index-url =http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
[list]
format=columns
EOF
--安装配置PyInstaller
pip3 install redis
pip3.8 install wheel
pip3.8 install PyInstaller
--查看安装了哪些软件
[root@mysql1 ~]# pip3 list
Package Version
------------------------- -------
altgraph 0.17.3
async-timeout 4.0.2
pip 19.3.1
pyinstaller 5.11.0
pyinstaller-hooks-contrib 2023.3
redis 4.5.5
setuptools 67.8.0
wheel 0.40.0
4、PyInstaller打包软件
pyinstaller -w -F -n redis_health_check_rhel7_v1.5 -F redis_health_check_v1.5.py