CentOS7上源码安装Python3.11_yum源只能安装到3.6
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
sed -i -e 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
换阿里云源
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache fast -y
安装依赖
yum -y install zlib # 没有会报错 zipimport.ZipImportError: can't decompress data; zlib not available
yum -y install sqlite-devel # 解决 sqlachemy sqlite 报错的问题:ModuleNotFoundError: No module named 'pysqlite2'
yum -y install python-devel # 暂时无用
# yum -y install openssl-devel # 不安装的话, https加密会报错 AssertionError: Python 2.6+ and OpenSSL required for SSL
yum -y install bzip2-devel # 不安装的话, matplotlib 报错 ModuleNotFoundError: No module named '_bz2'
yum -y install tk-devel # 不安装的话, matplotlib 报错 ModuleNotFoundError: No module named '_tkinter'
yum -y install tkinter # 安装完tk之后, 尽管不调用这个库, 打包之后的文件也会大3M
yum -y install gcc gcc-c++ # 以前不会,不知道什么情况出现报错 configure: error: no acceptable C compiler found in $PATH
yum -y install libffi-devel # 安装uwsgi时报错ModuleNotFoundError: No module named '_ctypes'的解决办法
yum -y install postgresql-devel # 安装psycopg2时报错pg_config is required to build psycopg2 from source. Please add the directory
yum -y install gdal gdal-devel # gdal相关告警
安装G++7.3
yum install centos-release-scl -y
yum install devtoolset-7 -y
cat >> /etc/bashrc <<'EOF'
source /opt/rh/devtoolset-7/enable
EOF
source /opt/rh/devtoolset-7/enable
g++ --version
安装openssl
wget http://www.openssl.org/source/openssl-1.1.1.tar.gz --no-check-certificate
tar -zxvf openssl-1.1.1.tar.gz
cd openssl-1.1.1
./config --prefix=/usr/local/openssl shared zlib
make
make install
rm -rf /usr/bin/openssl
rm -rf /usr/lib64/libssl.so.1.1
rm -rf /usr/lib64/libcrypto.so.1.1
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/
openssl version
安装Python3.11
rm -rf /usr/local/python3
curl -L -o Python-3.11.3.tgz https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tgz
tar -zxvf Python-3.11.3.tgz
cd Python-3.11.3
./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --with-openssl=/usr/local/openssl --with-openssl-rpath=auto
make -j $(nproc)
make install
#或者 sudo make altinstall
cd ..
# 不加下面变量的话,打包会失败
echo /usr/local/python3/lib > /etc/ld.so.conf.d/python3.conf
ldconfig
# ldd查看关联的库
ldd /usr/local/python3/bin/python3
# 删除软连接
rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3
# 创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
如果采用pip3 install时报错:python3: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or directory
,可通过下面命令解决
cp /usr/local/python3/lib/libpython3.11.so.1.0 /usr/lib64/
安装库
pip3 install -r ./requirements.txt -i http://172.18.0.69:8081/repository/pip-group/simple/ --trusted-host 172.18.0.69
编译二进制
/usr/local/python3/bin/pyinstaller manage.spec -y
./manage runserver 0.0.0.0:8000 --noreload
CentOS7 Install Python3.11.3.rpm
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/python3.11-3.11.2-2.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/chkconfig-1.19.1-1.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/python3.11-libs-3.11.2-2.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/python3.11-libs-3.11.2-2.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/glibc-2.28-225.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/glibc-common-2.28-225.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/glibc-langpack-zh-2.28-196.el8.x86_64.rpm
评论区