在 CentOS 8/CentOS 7 上安装 Python 3.9 |在 CentOS 8/CentOS 7 上安装 Python 3.9 |在 CentOS 8/CentOS 7 上安装 Python 3.9 |在 CentOS 8/CentOS 7 上安装 Python 3.9 |
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

在 CentOS 8/CentOS 7 上安装 Python 3.9 |

发表 admin at 2025年2月28日
类别
  • 未分类
标签

在今天的指南中,您将学习如何在 CentOS 8/CentOS 7 Linux 系统上安装 Python 3.9。 Python 是一种通用的、解释性的高级编程语言,最初由 Guido van Rossum 创建。 Python 的创建是为了简单性、深度集成和强大的可扩展性。您可以使用强大的库和工具(包括 Django、Pygame、Matplotlib、Plotly 等)通过 Python 实现更多功能。

在接下来的部分中,我们将了解 CentOS 8/CentOS 7 上 Python 3.9 的安装步骤。如果您对 Python 3.9 中提供的功能的完整列表感兴趣,请查看官方发行说明。

在 CentOS 8/CentOS 7 上安装 Python 3.9

Python 是一个跨平台软件包,这意味着它可以在 Linux、Windows、macOS 和 BSD 系统上运行。截至本文更新时,Python 3.9 的最新版本是 Python 版本。这是本教程中将安装的 Python 版本。

第1步:安装Python依赖项

以 root 或具有 sudo 权限的用户身份登录 CentOS 8/CentOS 7 系统。

ssh username@serveripaddress

然后进行系统更新

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

升级后重新启动,然后再继续安装依赖项

sudo reboot

安装在 CentOS 8/CentOS 7 上构建 Python 3.9 所需的软件开发工具:

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

确认 gcc 可用:

$ gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

第 2 步:下载最新的 Python 3.9 存档

确保 wget 已安装:

sudo yum install wget -y

使用 wget 下载最新的 Python 3.9 版本。

wget https://www.python.org/ftp/python/3.9.17/Python-3.9.17.tgz

使用 tar 提取存档文件:

tar xvf Python-*.tgz

切换到从文件提取中创建的目录:

cd Python-3.9*/

步骤 3:在 CentOS 8/CentOS 7 上安装 Python 3.9

运行以下命令来配置 Python 安装。

./configure --enable-optimizations --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"

成功输出示例:

....
checking for the Linux getrandom() syscall... yes
checking for the getrandom() function... yes
checking for library containing shm_open... -lrt
checking for sys/mman.h... (cached) yes
checking for shm_open... yes
checking for shm_unlink... yes
checking for pkg-config... /usr/bin/pkg-config
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... yes
checking for --with-ssl-default-suites... python
checking for --with-builtin-hashlib-hashes... md5,sha1,sha256,sha512,sha3,blake2
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup.local
creating Makefile

在 CentOS 8/CentOS 7 上构建 Python 3.9:

sudo make altinstall

请耐心等待,因为这需要相当长的时间,具体取决于系统中 CPU 核心的数量。如果成功,您应该收到如下消息:

....
running install_scripts
copying build/scripts-3.9/pydoc3.9 -> /usr/local/bin
copying build/scripts-3.9/idle3.9 -> /usr/local/bin
copying build/scripts-3.9/2to3-3.9 -> /usr/local/bin
changing mode of /usr/local/bin/pydoc3.9 to 755
changing mode of /usr/local/bin/idle3.9 to 755
changing mode of /usr/local/bin/2to3-3.9 to 755
rm /usr/local/lib/python3.9/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py
rm -r /usr/local/lib/python3.9/lib-dynload/__pycache__
/usr/bin/install -c -m 644 ./Misc/python.man \
	/usr/local/share/man/man1/python3.9.17
if test "xupgrade" != "xno"  ; then \
	case upgrade in \
		upgrade) ensurepip="--altinstall --upgrade" ;; \
		install|*) ensurepip="--altinstall" ;; \
	esac; \
	 ./python -E -m ensurepip \
		$ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpxqejw3c3
Processing /tmp/tmpxqejw3c3/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmpxqejw3c3/pip-22.0.4-py3-none-any.whll
Installing collected packages: setuptools, pip
  WARNING: The script easy_install-3.9 is installed in '/usr/local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script pip3.9 is installed in '/usr/local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
...

步骤 4:检查 Python 3.9 安装

运行以下命令以确认在 CentOS 8/CentOS 7 上成功安装 Python 3.9:

$ python3.9 --version
Python 3.9.17

Pip3.9 也必须已安装:

$ pip3.9 --version
pip 22.0.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

升级点

$ /usr/local/bin/python3.9 -m pip install --upgrade pip
Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (22.0.4)
Collecting pip
  Downloading pip-22.2.2-py3-none-any.whl (2.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 73.2 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.0.4
    Uninstalling pip-22.0.4:
      Successfully uninstalled pip-22.0.4
Successfully installed pip-22.2.2

使用 pip3.9 安装 awscli 的示例:

$ pip3.9 install awscli --user
Collecting awscli
  Downloading awscli-1.25.49-py3-none-any.whl (3.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.9/3.9 MB 65.8 MB/s eta 0:00:00
Collecting PyYAML<5.5,>=3.10
  Downloading PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl (630 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 630.1/630.1 kB 21.8 MB/s eta 0:00:00
Collecting colorama<0.4.5,>=0.2.5
  Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting docutils<0.17,>=0.10
  Downloading docutils-0.16-py2.py3-none-any.whl (548 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 548.2/548.2 kB 21.2 MB/s eta 0:00:00
Collecting s3transfer<0.7.0,>=0.6.0
  Downloading s3transfer-0.6.0-py3-none-any.whl (79 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 79.6/79.6 kB 11.7 MB/s eta 0:00:00
Collecting botocore==1.27.49
  Downloading botocore-1.27.49-py3-none-any.whl (9.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.0/9.0 MB 86.8 MB/s eta 0:00:00
Collecting rsa<4.8,>=3.1.2
  Downloading rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting urllib3<1.27,>=1.25.4
  Downloading urllib3-1.26.11-py2.py3-none-any.whl (139 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 139.9/139.9 kB 28.9 MB/s eta 0:00:00
Collecting jmespath<2.0.0,>=0.7.1
  Downloading jmespath-1.0.1-py3-none-any.whl (20 kB)
Collecting python-dateutil<3.0.0,>=2.1
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 51.3 MB/s eta 0:00:00
Collecting pyasn1>=0.1.3
  Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.1/77.1 kB 19.1 MB/s eta 0:00:00
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: pyasn1, urllib3, six, rsa, PyYAML, jmespath, docutils, colorama, python-dateutil, botocore, s3transfer, awscli
Successfully installed PyYAML-5.4.1 awscli-1.25.49 botocore-1.27.49 colorama-0.4.4 docutils-0.16 jmespath-1.0.1 pyasn1-0.4.8 python-dateutil-2.8.2 rsa-4.7.2 s3transfer-0.6.0 six-1.16.0 urllib3-1.26.11

以下是我们网站上有关 Python 的更多指南:

  • 学习 Python 编程的最佳书籍
  • 在 CentOS 8/CentOS 7 上安装 Python 3.8
  • 使用 Apache 和 mod_wsgi 在 CentOS 7 上部署 Python 3 Django 应用程序
  • 如何在 Debian 上安装 Python 和 Django
  • 在 CentOS 8/RHEL 8 上安装 Python 3/Python 2.7
©2015-2025 Norria support@norria.com