Install Python 3.9 on CentOS 8 / CentOS 7

本文将指导您如何在 CentOS 8 和 CentOS 7 上安装 Python 3.9。首先更新系统并安装依赖,然后下载 Python 3.9 最新归档文件并进行编译安装。安装完成后,通过检查 Python 3.9 是否成功安装来验证过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In today’s guide you’ll learn to install Python 3.9 on CentOS 8 / CentOS 7 Linux system. Python is general-purpose, interpreted and high-level programming language originally created by Guido van Rossum. Python is created for simplicity, deep integration and great extensibility. You can achieve much more with Python using powerful libraries and tools, including Django, Pygame, Matplotlib, Plotly, e.t.c.

In the next sections we look at the installation steps of Python 3.9 on CentOS 8 / CentOS 7. If you’re interested in a full list of features shipped in Python 3.9 check the official release notes.

Install Python 3.9 on CentOS 8 / CentOS 7

Python is a cross-platform software package meaning it can run on Linux, Windows, macOS, and BSD systems. As of this article update, the exact latest release of Python 3.9 is version Python 3.9.7. This is the version of Python that will be installed in this tutorial.

Step 1: Install Python Dependencies

Login to your CentOS 8 / CentOS 7 system as root or user with sudo privileges.

ssh *username*@*serveripaddress*

Then do system update

sudo yum -y install epel-release
sudo yum -y update

Reboot after the upgrade before you continue to install dependencies

sudo reboot

Install required software development tools required to build Python 3.9 on CentOS 8 / CentOS 7:

sudo yum groupinstall "Development Tools" -y
sudo yum install openssl-devel libffi-devel bzip2-devel -y

Confirm gcc is available:

$ *gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4) Copy
### CentOS 8 上离线安装 Python 3.9 #### 准备工作环境 为了在 CentOS 8 中成功离线安装 Python 3.9,需先在线机器上准备好必要的依赖库和工具。这一步骤确保所有必需文件被正确获取并打包到可移植介质中以便后续用于目标系统的离线部署。 ```bash sudo dnf groupinstall "Development Tools" sudo dnf install openssl-devel bzip2-devel libffi-devel wget tar gcc make zlib-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel ``` 上述命令会安装编译 Python 所需的各种开发库和支持软件[^1]。 #### 下载源码包 访问官方 Python 网站或其他可信镜像站点下载对应版本的 Python 源代码压缩包至本地计算机: ```bash cd /tmp/ wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz tar -xf Python-3.9.0.tgz cd Python-3.9.0 ``` 此过程将解压所下载的 Python 3.9 压缩包,并进入其目录准备下一步配置与构建操作。 #### 编译与安装 完成前期准备工作之后,在具备网络连接的工作站执行如下指令来编译并安装 Python 至指定路径(如 `/usr/local/python3`),随后创建软链接方便调用新版本解释器及其配套工具: ```bash ./configure --prefix=/usr/local/python3 --enable-shared LDFLAGS="-Wl,-rpath,/usr/local/python3/lib" make && sudo make altinstall ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip3 python3 -V pip3 -V ``` 通过以上步骤可以验证 Python 和 Pip 是否已正确设置完毕以及具体版本信息[^2]。 #### 处理常见错误 如果遇到 `No module named '_ssl'` 错误提示,则可能是由于缺少 OpenSSL 开发库所致;此时应确认已经按照前述指导完成了相应依赖项的预装工作。另外还需注意检查系统环境变量 PATH 设置是否恰当指向新的 Python 可执行程序位置[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值