blog.zhuohua.store's Archiver

admin 发表于 2019-9-22 10:30

CentOS6安装Python3

笺注:如果删除了旧版本的Python2,Yum命令会无法使用,可能还会出现很多问题,所以Python3另外安装在其他目录就好了。

实验中,操作系统的版本信息:
[root@centos6 ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@centos6 ~]#
[root@centos6 ~]# uname -r
2.6.32-696.el6.x86_64

就算是最小化安装,CentOS6.9也是已经安装了低版本的Python2:
[root@centos6 ~]# python --version
[color=Purple]Python 2.6.6[/color]
[root@centos6 ~]#
[root@centos6 ~]# ll /usr/bin/python
[color=Purple]-rwxr-xr-x. 2 root root 4864 8月  18 2016 /usr/bin/python[/color]
[root@centos6 ~]# ll /usr/bin/python2
[color=Purple]lrwxrwxrwx. 1 root root 6 7月   5 2018 /usr/bin/python2 -> python[/color]



先安装依赖软件包:
yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel wget gcc-c++ make

下载Python3的软件包:[url]https://pan.baidu.com/s/1LKMfYjiwAycZeDIFfJl6dQ[/url]   提取码:usyh

安装Python3:
tar -zxvf Python-3.6.8.tgz
mv Python-3.6.8 /usr/local/
cd /usr/local/Python-3.6.8/
./configure
make
make install

给Python3创建新链接:
[root@centos6 ~]# ln -s /usr/local/bin/python3.6 /usr/bin/python3
[root@centos6 ~]#
[root@centos6 ~]# ll /usr/bin/python3
[color=Purple]lrwxrwxrwx 1 root root 24 2月   8 11:51 /usr/bin/python3 -> /usr/local/bin/python3.6[/color]


Python2和Python3实现共存了:
[root@centos6 ~]# python --version
[color=Purple]Python 2.6.6[/color]
[root@centos6 ~]#
[root@centos6 ~]# python3 --version
[color=Purple]Python 3.6.8[/color]


测试:
[attach]19249[/attach]

[attach]19250[/attach]



######

创建Python3脚本:
[root@centos6 ~]# cat xx.py
#coding=utf-8

def func1(): #自定义函数

        print('Welcome to zhuohua.') #函数的操作

if __name__ == '__main__':

        func1() #执行函数


给予所有系统用户运行这个Python3脚本的权限:
[root@centos6 ~]# ll xx.py
-rw-r--r-- 1 root root 147 2月   8 12:00 xx.py
[root@centos6 ~]#
[root@centos6 ~]# chmod a+x xx.py
[root@centos6 ~]#
[root@centos6 ~]# ll xx.py
[color=Purple]-rwxr-xr-x[/color] 1 root root 147 2月   8 12:00 xx.py
[root@centos6 ~]#


运行Python3脚本:
[root@centos6 ~]# python3 xx.py
[color=Purple]Welcome to zhuohua.[/color]
[root@centos6 ~]#





相关文章:
[url=http://blog.zhuohua.store/viewthread.php?tid=366&page=1&extra=#pid443]CentOS7安装Python3[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=352&page=1&extra=#pid429]CentOS8安装Python3[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=120&page=1&extra=#pid121]Win7/Windows2008R2安装Python3[/url]

[url=http://blog.zhuohua.store/viewthread.php?tid=455&page=1&extra=#pid883]Python3脚本管理Oracle11gR2[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=152&page=1&extra=#pid153]Python3脚本管理Linux下的MySQL[/url]

[url=http://blog.zhuohua.store/viewthread.php?tid=168&page=1&extra=#pid169]CentOS6使用Python3脚本备份站点(Zabbix)+crontab计划任务[/url]

[url=http://blog.zhuohua.store/viewthread.php?tid=209&page=1&extra=#pid210]最小化安装CentOS6[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=452&page=1&extra=#pid880]CentOS6_Yum仓库[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=281&page=1&extra=#pid284]CentOS6使用新Yum源+EPEL[/url]





#################################
#################################
[url=https://weidian.com/?userid=823531601&wfr=wx&sfr=app&source=shop]亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^[/url]

[url=https://weidian.com/item.html?itemID=905482571142042467259&wfr=wx&sfr=app&source=goods_home]肉食注意|豪气鸭掌;包邮【七猩猩】 豪气鸭掌8只盒装共176g/元气鸭翅5只袋装共210g[/url]
[url=https://weidian.com/item.html?itemID=905482571142042467259&wfr=wx&sfr=app&source=goods_home][attach]2123[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571141668117004&wfr=wx&sfr=app&source=goods_home]包邮【七猩猩_大大大礼包_五福临门】坚果休闲零食7袋大礼盒 1459g,专属大大,大大大礼包五福临门,七款坚果共7包美味组合[/url]
[url=https://weidian.com/item.html?itemID=905482571141668117004&wfr=wx&sfr=app&source=goods_home][attach]2121[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571142731502729&wfr=wx&sfr=app&source=goods_home]FaSoLa夏季厚底情侣儿童洗澡防滑漏水浴室拖鞋居家凉拖鞋轻便柔软[/url]
[url=https://weidian.com/item.html?itemID=905482571142731502729&wfr=wx&sfr=app&source=goods_home][attach]2122[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571142534746508&wfr=wx&sfr=app&source=goods_home]薇语馨8072女装春季新款文艺修身拼色立领绣花连衣裙中长裙[/url]
[url=https://weidian.com/item.html?itemID=905482571142534746508&wfr=wx&sfr=app&source=goods_home][attach]2118[/attach][/url]

[url=https://weidian.com/item.html?itemID=905482571142545825630&wfr=wx&sfr=app&source=goods_home]薇语馨1313深V性感女装紧身包臀透纱夜店裙无袖打底网纱连衣裙[/url]
[url=https://weidian.com/item.html?itemID=905482571142545825630&wfr=wx&sfr=app&source=goods_home][attach]2120[/attach][/url]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.