云网牛站
所在位置:首页 > 初入Linux圈 > 在CentOS 8/CentOS 7系统中安装Python 3.9.1和Pip3.9的方法

在CentOS 8/CentOS 7系统中安装Python 3.9.1和Pip3.9的方法

2021-01-29 11:31:26作者:叶云稿源:云网牛站

本文介绍在CentOS 8/CentOS 7/RHEL Linux系统中安装Python-3.9.1.tgz和Pip3.9的方法,同样的方法可用在安装其它Python 3.9版本上。

在CentOS 8/CentOS 7系统中安装Python 3.9.1和Pip3.9的方法

 

一、安装Python 3.9.1依存关系

以root或具有sudo特权的用户登录到CentOS 8/CentOS 7系统:

$ ssh username@serveripaddress

注:如果无此场景请不要做这步操作,直接进行下面的系统更新即可。

然后进行系统更新:

sudo yum -y update

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

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)

参考:现在可以在CentOS 8系统下用命令安装GCC 8.3.1版本

 

二、下载最新的Python 3.9.1文件

确保已安装wget:

sudo yum install wget -y

使用wget下载新的Python 3.9版本,如Python-3.9.1.tgz:

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

注:或从https://www.python.org/downloads/中下载。

使用tar提取存档文件:

tar xvf Python-3.9.1.tgz

切换到从文件解压缩创建的目录:

cd Python-3.9*/

 

三、在CentOS 8/CentOS 7中安装Python 3.9.1

运行以下命令以配置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.1:

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

 

四、检查CentOS 8/CentOS 7中Python 3.9.1和Pip3.9安装

运行以下命令以确认在CentOS 8/CentOS 7中成功安装了Python 3.9.1:

$ python3.9 --version

Python 3.9.1

Pip3.9也必须已经安装:

$ pip3.9 --version

pip 20.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

至此,确定系统上已安装Python 3.9.1和Pip3.9。

 

相关主题

在CentOS 8系统中安装pip3和pip2,及使用pip管理Python软件包

子频道
精选文章
热门文章