CentOS7.3编译安装python3.6
一、前言
最近迷上了python,所以准备开始上手python。由于python2维护较少,python3必然是趋势了,所以我准备用python3.6学习python。CentOS7.3默认安装的是python2.7,所以我需要从官网上下载python3.6并编译安装python3.6,但是比较尴尬的是,CentOS的yum环境支持python2而不支持python3,所以需要通过一些小小的修改,才能在正常的使用python3.6的同时也能正常的使用yum。这其实没什么难的,python3就按照正常的编译安装即可,yum环境支持只需要在/usr/bin/yum的以及/usr/libexec/urlgrabber-ext-down的第一行做一些软链接的修改即可。详细内容请看操作步骤。
二、操作步骤
1.编译环境准备
yumgroupinstall'DevelopmentTools' yuminstallzlib-develbzip2-developenssl-develncurese-devel
2.下载python3.6源码包
wgethttps://www.python.org/ftp/python/3.6.2/Python-3.6.2rc1.tar.xz
3.解压压缩包
tar-xvfPython-3.6.2rc1.tar.xz
4.编译安装步骤
cdPython-3.6.2rc1/ ./configure--prefix=/usr/local/python3 make&&makeinstall
5.1修改软链接以及相关操作 mv/usr/bin/python2.7/usr/bin/python2.7.5#先更改python2.7的名字 rm/usr/bin/python-r#删除原先的软链接 ln-s/usr/bin/python2.7.5/usr/bin/python2.7#将python2.7环境软链接至/usr/bin/python2.7 ln-s/usr/local/python3/bin/python3.6/usr/bin/python#将python3.6环境软链接至/usr/bin/python ln-s/usr/local/python3/bin/pip3/usr/bin/pip#将pip3软链接至/usr/bin/pip python-V#查看目前使用的python版本 Python3.6.2rc1 pip-V#查看pip版本 pip9.0.1from/usr/local/python3/lib/python3.6/site-packages(python3.6) python2.7-V Python2.7.5#当然你也可以使用python2.7.5 yumrepolist#测试yum环境,yum环境失效 [root@localhostbin]#yumrepolist Loadedplugins:fastestmirror,langpacks Loadingmirrorspeedsfromcachedhostfile File"/usr/libexec/urlgrabber-ext-down",line28#报错位置 exceptOSError,e: ^ SyntaxError:invalidSyntax File"/usr/libexec/urlgrabber-ext-down",line28 exceptOSError,e: ^ SyntaxError:invalidSyntax Exitingonusercancel 5.2恢复yum环境相关操作 vi/usr/bin/yum 第一行修改为 #!/usr/bin/python2.7 vi/usr/libexec/urlgrabber-ext-down 第一行修改为 #!/usr/bin/python2.7 5.3测试yum环境 yumrepolist#再次测试yum环境,yum环境正常 Loadedplugins:fastestmirror,langpacks Loadingmirrorspeedsfromcachedhostfile repoidreponamestatus cdcd9,363 centoscentosrepository9,363 epelextrapackagesforenterpriselinux11,349 repolist:30,075原文链接:https://www.f2er.com/centos/376860.html