CentOS系统python默认版本由python2改为python3
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CentOS系统python默认版本由python2改为python3,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2049字,纯文字阅读大概需要3分钟。
内容图文
![CentOS系统python默认版本由python2改为python3](/upload/InfoBanner/zyjiaocheng/957/4356ebe05c204d8f9ddb93400f642591.jpg)
一.了解
CentOS中如果安装有yum,一般会有python2的某个版本。命令行键入python,出现的python2的环境:
[root@instance-hrnebyqu src]# python Python 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
我们希望将python这个shell指令连接到python3的版本。这里首先装python3,然后将python连接到python3上。
由于路径添加到了bash_profile文件中的PATH中了,因此环境变量不需要再改了。如果没有天津爱到哦环境变量则需要
vim ~/.bash_profile
把Python3的路径加上,然后重载bash_profile这个文件
接着修改bashrc这个文件
vim ~/.bashrc
将python2和python3 的路径都写上,并将python指定为python3
alias python2=/usr/bin/python alias python3=/usr/local/python3/bin/python3 alias python=/usr/local/python3/bin/python3
这样,命令行开python就是python3了。
[root@instance-hrnebyqu src]# python Python 3.6.6 (default, Jul 4 2019, 12:00:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information.
注意:
在centos中,用于软件安装的yum指令是调用python昨晚命令解释器的,因此其默认版本为Python2,如果改成python3,会由于2和3的兼容性问题导致yum可能出现故障。因此需要特别注意。
yum 的路径在
/usr/bin/yum
可以看一下yum文件
#!/usr/bin/python import sys try: import yum except ImportError: print >> sys.stderr, """There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: %s Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version of Python, which is: %s If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq """ % (sys.exc_value, sys.version) sys.exit(1) sys.path.insert(0, '/usr/share/yum-cli') try: import yummain yummain.user_main(sys.argv[1:], exit_code=True) except KeyboardInterrupt, e:
可以看到,开头默认了解释器为/usr/bin/python。如果yum因为修改了python解释器出现bug,可以将这个改成/usr/bin/python2.x即可。
内容总结
以上是互联网集市为您收集整理的CentOS系统python默认版本由python2改为python3全部内容,希望文章能够帮你解决CentOS系统python默认版本由python2改为python3所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。