在Centos6.5中配置python3

1、下载Python安装包
源码包下载地址:https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
使用rz命令把下载下来的tar包上传到服务器上。
在Centos6.5中配置python3
2、解压下载好的tar包:
输入命令:tar -xzvf Python-3.6.0.tgz

3、创建安装目录:
mkdir -p /usr/local/python3

4、进入解压后的目录,编译安装:
(1)cd Python-3.6.0
(2)./configure --prefix=/usr/local/python3
(3)make && make install

5、把python2的软链接删除后重新建立python2的软链接:
(1)cd /usr/bin 在这个目录下先查看下python2的版本:
在Centos6.5中配置python3
(2)rm -rf python
(3)ln -s /usr/bin/pytest2.6 /usr/bin/python2(因为我的系统中的python是2.6版本的,需要查看自己系统中的python2版本)
创建后如图:
在Centos6.5中配置python3

6、修改yum中的python引用
还是在 /usr/bin这个路径下,vi yum
在Centos6.5中配置python3
修改后,:wq保存并退出

7、创建python3的软链接:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
创建后:
在Centos6.5中配置python3
8、将python3的路径 添加到环境变量中:
vi /etc/profile
在Centos6.5中配置python3
在最后面添加一句:
export PATH=$PATH:/usr/local/python3/bin
:wq保存并退出
执行:sourcr /etc/profile,是加入的环境变量生效

测试:
输入python:
在Centos6.5中配置python3
输入python2:
在Centos6.5中配置python3
输入pip -V:
在Centos6.5中配置python3
如果使用pip -V没有反应或者报错,也给pip做个软链接:
在Centos6.5中配置python3
查看生成软链接的pip
在Centos6.5中配置python3
至此,python3已经配置完毕!

注:使用pip install XXX时,可以安装完成,但是会提示:
“You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the ‘pip install --upgrade pip’ command.”
在Centos6.5中配置python3
这时候,直接输入:
pip install --upgrade pip
把pip升级到最新版本