centos7 arm服务器编译安装python 3.8

前言

        CentOS (Community Enterprise Operating System) 是一种基于 Red Hat Enterprise Linux (RHEL) 进行源代码再编译并免费提供给用户的 Linux 操作系统。

        CentOS 7 采用了最新的技术和软件包,并提供了强大的功能和稳定性。它适用于各种服务器和工作站应用场景,并具有广泛的支持和用户社区,这里我详细讲解下Python 3.8编译安装,其他linux环境也可借鉴。

软件准备

1、Python的安装包

可以在Python官网下载,这里提供一个3.8版本的Python包下载地址:Python-3.8.18.tgz

2、centos7系统

系统下载地址:centos-altarch-7.9.2009-isos-aarch64安装包下载_开源镜像站-阿里云 (aliyun.com)

推荐Minimal-2009版本的

centos7 arm服务器编译安装python 3.8_第1张图片

添加系统源

vim /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://repo.huaweicloud.com/centos-altarch/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://repo.huaweicloud.com/centos-altarch/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://repo.huaweicloud.com/centos-altarch/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64
enabled=1

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://repo.huaweicloud.com/centos-altarch/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64
3、系统依赖包

通过yum命令将缺少的包安装上,这样运行编译后的Python的时候报缺少模块错误

yum install zlib* bzip2* libffi* sqlite* gdbm* uuid lzma* tk* libssl* openssl* xz*

开始编译

1、解压tgz包或者tar.gz包

tar -xvzf <源码包>

2、开始构建

./configure --prefix=/usr/local/python3.8 --enable-optimizations

如构建后,使用python3过程中出现错误:

“ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+”:

centos7 arm服务器编译安装python 3.8_第2张图片

查看这篇文章编译安装openssl:【centos7 arm服务器编译安装openssl 1.1.1版本】

如何构建命令改成这样

./configure --prefix=/usr/local/python3.8 --with-openssl=/usr/local/openssl-1.1.1 --enable-optimizations

3、编译

make && make install

4、编译完成后,配置环境:

echo 'export PATH=/usr/local/python3.8/bin:$PATH' >> ~/.bashrc

source ~/.bashrc

ln -sf /usr/local/python3.8/bin/python3.8 /usr/bin/python3

ln -sf /usr/local/python3.8/bin/pip3.8 /usr/bin/pip3

输入python3 -V结果为python3.8就代表编译完成。

5、配置pip源

vim /etc/pip.conf

复制下面的内容并保存

[global]
timeout = 60
index-url =  https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host =
    pypi.tuna.tsinghua.edu.cn

完毕!!!

你可能感兴趣的:(aarch64Linux,arm开发,服务器,python)