centos7平台安装python3

一、场景描述

centos7系统默认安装的python是v2版本的,但有些程序需要python3程序支持,如何在centos7中部署python3呢?

二、过程

2.1 安装python3软件包

安装EPEL和IUS软件源

yum install epel-release -y
yum install https://centos7.iuscommunity.org/ius-release.rpm -y

安装Python3.6

yum install python36u -y
yum install python36u-devel -y

安装pip3

yum install python36u-pip -y

2.2、修改系统默认python为python3版本

1、默认python程序进行备份

mv /usr/bin/python   /usr/bin/pythonbak

 2、修改默认python为python3

ln -s /usr/bin/python3.6 /usr/bin/python

3、修改yum的默认python版本

[root@dba ~]# cat /usr/bin/yum
#!/usr/bin/python  -->修改为 #!/usr/bin/python2.7
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

 2.3 修改pip安装源

修改系统pip安装源
在家目录下新建.pip文件夹,进入文件夹新建文件pip.conf之后写入相应镜像网站地址

cd ~
mkdir .pip
cd .pip
vim pip.conf

#进入后添加以下内容,保存退出.
[global]
index-url = https://mirrors.aliyun.com/pypi/simple

修改pipenv安装源
在自己的虚拟环境中找到Pipfile文件,将其中的url = "https://pypi.org/simple"修改为你需要的国内镜像,如https://mirrors.aliyun.com/pypi/simple/

[root@localhost]# vim Pipfile 


[[source]]
name = "pypi"
url = "https://pypi.org/simple" # 改为url = "https://mirrors.aliyun.com/pypi/simple/"
verify_ssl = true

[dev-packages] #这里是开发环境专属包,使用pipenv install --dev package来安装专属开发环境的包

[packages] # 全部环境的通用包,安装在这里.

[requires]
python_version = "3.6"

 

三、总结

1、yum程序依赖python,修改系统默认python版本后,注意修改yum程序的python信息

posted @ 2020-04-28 13:44  雪竹子  阅读(303)  评论(0编辑  收藏  举报