Warning: file_exists(): open_basedir restriction in effect. File(/wp-cache-blog.topstalk.coma70cd7bb698f890aab7c4d0e4b1b1d53.php) is not within the allowed path(s): (/www/wwwroot/Topstalk.com/:/tmp/:/RAMDisk/) in /www/wwwroot/Topstalk.com/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 100
 CentOS7升级Python3 – 沫延说
沫延说
沫延说

Warning: Trying to access array offset on value of type bool in /www/wwwroot/Topstalk.com/wp-content/themes/MDx/single.php on line 71
CentOS7升级Python3
CentOS7升级Python3

前言

有时候应用需要Python3的环境,然而CentOS7默认自带Python2,可以使用以下方法升级下

升级Python3还需要修复yum对Python2的依赖

 

方案

养成良好习惯,以下均按标准部署流程执行,以Python-3.9.2版本为例

首先下载源码并解压:

wget -O /usr/src/Python-3.9.2.tgz https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz
cd /usr/src/
tar -zxvf Python-3.9.2.tgz
cd Python-3.9.2

配置安装位置并进行编译和测试,最后安装

./configure --prefix=/usr/local/python3
make
make test
make install

备份原Python2的可执行文件和链接,随后建立Python3的链接

mv /usr/bin/python /usr/bin/python2
mv /usr/bin/pip /usr/bin/pip2
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

修复系统依赖的链接路径

编辑/usr/libexec/urlgrabber-ext-down和/usr/bin/yum两个文件

将#!后面的python路径为Python2的路径,即,将/usr/bin/python更改为/usr/bin/python2,/usr/bin/pip更改为/usr/bin/pip2

结语

此时默认的Python版本已经切换为Python3,即使用Python和pip命令时将会使用Python3,同时系统yum对Python2的依赖也已经修复完成,不影响yum的功能

 

感谢您阅读CentOS7升级Python3

及时获取更多文章,欢迎关注“Topstalk”微信订阅号

Thank you for reading the CentOS7升级Python3

Get more articles in time,Welcome to follow the "Topstalk" WeChat subscription account

Morton.L

文章作者

发表评论

textsms
account_circle
email

Warning: Trying to access array offset on value of type bool in /www/wwwroot/Topstalk.com/wp-content/themes/MDx/single.php on line 200
style="background-image:linear-gradient(to bottom, rgba(0,0,0,0) 45%,rgba(0,0,0,0.7) 100%),url(https://blog.topstalk.com/wp-content/themes/MDx/img/dpic.jpg");>

沫延说

CentOS7升级Python3
前言 有时候应用需要Python3的环境,然而CentOS7默认自带Python2,可以使用以下方法升级下 升级Python3还需要修复yum对Python2的依赖   方案 养成良好习惯,以下均按标准部…
扫描二维码继续阅读
2021-03-16