保留python2
找到python所在位置,把python指向python2.7备份
[[email protected] /usr/bin]# cd ~
[[email protected] ~]# whereis python
python: /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
[[email protected] ~]# cd /usr/bin/
[[email protected] /usr/bin]# ll python*
lrwxrwxrwx. 1 root root 7 2019-06-19 23:17 python -> python2
lrwxrwxrwx. 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
[[email protected] /usr/bin]# mv python python.bak
[[email protected] /usr/bin]# ll python*
下载安装python3
python下载地址:https://www.python.org/ftp/python/
# 在usr/local/下创建python3文件夹,并下载python3
[[email protected] /usr/bin]# cd /usr/local/
[[email protected] /usr/local]# mkdir python3
[[email protected] /usr/local]# cd python3/
[[email protected] /usr/local/python3]# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
[[email protected] /usr/local/python3]# tar -xvf Python-3.6.8.tgz
# 进入文件, 指定安装目录和编译安装
[[email protected] /usr/local/python3]# cd Python-3.6.8/
[[email protected] /usr/local/python3/Python-3.6.8/]# ./configure --prefix=/usr/local/python3
[[email protected] /usr/local/python3/Python-3.6.8]# make && make install
# 如果报zlib错
执行
mv /usr/bin/python.bak /usr/bin/python
yum install zlib* -y
mv /usr/bin/python /usr/bin/python.bak
再编译安装
# 添加软连接
[[email protected] /usr/local/python3/Python-3.6.8]# ln -s /usr/local/python3/bin/python3 /usr/bin/python
修改yum配置
yum安装依赖于python2,
[[email protected] /usr/local/python3]# sed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/bin/yum
[[email protected] /usr/local/python3]# sed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/libexec/urlgrabber-ext-down
修改pip配置
[[email protected] /usr/local/python3]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
pip源
mkdir ~/.pip
cd ~/.pip && touch pip.conf
cat >pip.conf<<EOF
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
EOF
window下修改
# 1、C:\Users\电脑用户\AppData\Roaming 文件夹中
# 2、新建 pip 文件夹并在文件夹中新建 pip.ini 配置文件
# 3、新增 pip.ini 配置文件内容
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
脚本文件
下载python3.6.8
yum install zlib* -y
mv /usr/bin/python /usr/bin/python.bak
mkdir /usr/local/python3
cd /usr/local/python3
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
tar -xf Python-3.6.8.tgz
cd Python-3.6.8/
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python
sed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/bin/yum
sed -i 's#/usr/bin/python#/usr/bin/python2#g' /usr/libexec/urlgrabber-ext-down
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
mkdir ~/.pip
cd ~/.pip && touch pip.conf
cat >pip.conf<<EOF
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
EOF
原文地址:https://www.cnblogs.com/ywsun/p/11335196.html
时间: 2024-10-28 09:48:58