Python3-在centos7.6上安装python3.6.1

官方python3.6.1下载地址https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz【超慢】
搜狐镜像地址http://mirrors.sohu.com/python/3.6.1/Python-3.6.1.tar.xz

# 开启yum的缓存功能,yum安装软件包是在线安装,开启缓存功能可以使得软件包被下载到本地,方便后续使用。
[root@master ~]# vim /etc/yum.conf 
cachedir=/opt/python3.6.1
keepcache=1
[root@master ~]# mkdir /opt/python3.6.1

# 配置网络yum源
[root@master ~]# cd /etc/yum.repos.d/
[root@master yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo

# 安装python3的依赖包
[root@master ~]# yum install libffi-devel wget sqlite-devel xz gcc atuomake zlib-devel openssl-devel epel-release git -y

# 编译安装python3.6.1
[root@master ~]# cd /usr/local/src/
[root@master src]# wget http://mirrors.sohu.com/python/3.6.1/Python-3.6.1.tar.xz
[root@master src]# ll
总用量 16480
-rw-r--r--. 1 root root 16872064 3月  21 2017 Python-3.6.1.tar.xz
[root@master src]# tar xf Python-3.6.1.tar.xz
[root@master src]# cd Python-3.6.1/
[root@master Python-3.6.1]# ./configure && make -j 4 && make install     

# 可以看到python3.6.1已经安装上去了,但是默认的还是2.7.5
[root@master ~]# python
python             python3            python3.6m         
python2            python3.6          python3.6m-config  
python2.7          python3.6-config   python3-config     
[root@master ~]# python -V
Python 2.7.5

# 由于centos7.6自带的是python2.7.5,现在安装python3.6.1,在使用python安装软件时可能会有冲突。
# 一个比较好的解决方法是:进入python3虚拟环境中安装软件。
[root@master ~]# python3 -m venv py3               # 安装虚拟环境,会在当前目录下生成一个py3目录
[root@master ~]# source /root/py3/bin/activate     # 激活py3虚拟环境,在虚拟环境中安装jumpserver
(py3) [root@master ~]# python -V
Python 3.6.1

猜你喜欢

转载自blog.csdn.net/weixin_36522099/article/details/109966802