当前位置:   article > 正文

CentOS7同时安装Python2 Python3

CentOS7同时安装Python2 Python3

安装python2.7

CentOS7上默认安装的是python2.7.5,在服务器上

首先安装epel扩展源:

yum -y install epel-release

然后安装python-pip

yum -y install python-pip
  1. [root@localhost ~]# python --version
  2. Python 2.7.5
  3. [root@localhost ~]# pip --version
  4. pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

安装完之后别忘了清除一下cache

yum clean all

安装python3

在官方网站下载

  1. wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
  2. tar -zxvf Python-3.6.2.tgz
  3. cd Python-3.6.2/
  4. ./configure --prefix=/usr/local
  5. make
  6. make install

Successfully installed pip-9.0.1 setuptools-28.8.0

  1. [root@localhost Python-3.6.2]# python --version
  2. Python 2.7.5
  3. [root@localhost Python-3.6.2]# python3 --version
  4. Python 3.6.2
  5. [root@localhost Python-3.6.2]# pip --version
  6. pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
  7. [root@localhost Python-3.6.2]# pip3 --version
  8. pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

在写Python代码的时候,文件头部都加上:

  1. #!/usr/bin/env python3
  2. # coding=utf-8

转载于:https://my.oschina.net/leeyisoft/blog/1510870

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/581378
推荐阅读
相关标签
  

闽ICP备14008679号