保留python2
找到python所在位置,把python指向python2.7备份
[root@sun /usr/bin]# cd ~[root@sun ~]# whereis pythonpython: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz[root@sun ~]# cd /usr/bin/[root@sun /usr/bin]# ll python*lrwxrwxrwx. 1 root root 7 2019-06-19 23:17 python -> python2lrwxrwxrwx. 1 root root 9 2019-06-19 23:17 python2 -> python2.7-rwxr-xr-x. 1 root root 7216 2018-10-31 07:46 python2.7[root@sun /usr/bin]# mv python python.bak[root@sun /usr/bin]# ll python*
下载安装python3
python下载地址:https://www.python.org/ftp/python/
# 在usr/local/下创建python3文件夹,并下载python3[root@sun /usr/bin]# cd /usr/local/[root@sun /usr/local]# mkdir python3[root@sun /usr/local]# cd python3/[root@sun /usr/local/python3]# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz[root@sun /usr/local/python3]# tar -xvf Python-3.6.8.tgz# 进入文件, 指定安装目录和编译安装[root@sun /usr/local/python3]# cd Python-3.6.8/[root@sun /usr/local/python3/Python-3.6.8/]# ./configure --prefix=/usr/local/python3[root@sun /usr/local/python3/Python-3.6.8]# make && make install# 如果报zlib错执行mv /usr/bin/python.bak /usr/bin/pythonyum install zlib* -y mv /usr/bin/python /usr/bin/python.bak再编译安装# 添加软连接[root@sun /usr/local/python3/Python-3.6.8]# ln -s /usr/local/python3/bin/python3 /usr/bin/python
修改yum配置
yum安装依赖于python2,
[root@sun /usr/local/python3]# sed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/bin/yum[root@sun /usr/local/python3]# sed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/libexec/urlgrabber-ext-down
修改pip配置
[root@sun /usr/local/python3]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
pip源
mkdir ~/.pipcd ~/.pip && touch pip.confcat >pip.conf<
window下修改
# 1、C:\Users\电脑用户\AppData\Roaming 文件夹中# 2、新建 pip 文件夹并在文件夹中新建 pip.ini 配置文件# 3、新增 pip.ini 配置文件内容[global]index-url = http://pypi.douban.com/simple[install]use-mirrors =truemirrors =http://pypi.douban.com/simple/trusted-host =pypi.douban.com
脚本文件
下载python3.6.8
yum install zlib* -ymv /usr/bin/python /usr/bin/python.bakmkdir /usr/local/python3cd /usr/local/python3wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgztar -xf Python-3.6.8.tgzcd Python-3.6.8/./configure --prefix=/usr/local/python3make && make installln -s /usr/local/python3/bin/python3 /usr/bin/pythonsed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/bin/yumsed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/libexec/urlgrabber-ext-downln -s /usr/local/python3/bin/pip3 /usr/bin/pipmkdir ~/.pipcd ~/.pip && touch pip.confcat >pip.conf<