在 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。Python 是由 Guido van Rossum 设计的通用、解释型和高级编程语言。Python 具有简单、深度集成和高可扩展性等特点。在接下来的部分中,我们将介绍如何在 CentOS 8 / CentOS 7 上的安装 Python 3.9。

Python 是一种跨平台的软件,这意味着它可以在 Linux、Windows、macOS 和 BSD 等多种系统上运行。

第 1 步:安装 Python 依赖项

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

$ ssh username@serveripaddress

然后进行系统更新:

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

升级后重启后再继续安装依赖:

sudo reboot

安装所需的开发工具:

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

确认 gcc 可用:

$ gcc --version
gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5)
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.9/Python-3.9.9.tgz

使用 tar 解压压缩包文件:

tar xvf Python-3.9.9.tgz

切换到从文件目录:

cd Python-3.9*/

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

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

./configure --enable-optimizations

输出如下所示:

....
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

请耐心等待,因为这需要一定的时间。安装成功后,应该会收到如下消息:

....
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.1
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-49.2.1-py3-none-any.whl
Processing /tmp/tmpxqejw3c3/pip-20.2.3-py2.py3-none-any.whl
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.
Successfully installed pip-20.2.3 setuptools-49.2.1

检查 Python 3.9 是否成功安装

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

$ python3.9 --version
Python 3.9.9

验证是否安装 Pip3.9 :

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

原创文章,作者:牛奇网,如若转载,请注明出处:https://www.niuqi360.com/linux/install-python-3-9-on-centos-8-and-centos-7/

发表评论

登录后才能评论