🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
https://www.cnblogs.com/mlgjb/p/7976561.html https://www.cnblogs.com/technologylife/p/6642615.html **一.下载** 把python3.7下载到/usr/local/src下 `[root@localhost /]# cd /usr/local/src/` `[root@localhost src]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz` `[root@localhost src]# tar xvJf Python-3.7.0.tar.xz` `[root@localhost src]# mv Python-3.7.0 /usr/local/python-3.7` `[root@localhost src]# cd /usr/local/python-3.7/` ***** **二.安装** 安装之前,首先安装两个python依赖的包: `[root@localhost python-3.7]# yum -y install zlib* libffi-devel` 配置编辑参数: `[root@localhost python-3.7]# ./configure --prefix=/usr/local/sbin/python-3.7` 编译和安装: `[root@localhost python-3.7]# make` `[root@localhost python-3.7]# make install` 安装完成后,若出现以下两行,说明安装成功; ``` Installing collected packages: setuptools, pip Successfully installed pip-10.0.1 setuptools-39.0.1 ``` 也可以用“echo $?”查看,结果为0说明安装成功; ``` [root@localhost python-3.7]# echo $? 0 ``` 然后就可以使用python3了。 ``` [root@localhost python-3.7]# /usr/local/sbin/python-3.7/bin/python3 Python 3.7.0 (default, Sep 30 2018, 09:36:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ``` 以下不建议做,做了后,yum会出很多问题 可以看到,虽然成功安装了python3.7,但是执行起来命令特别长,可以把python命令指向到到python3。 首先查看python命令的绝对路径,可以看到它是通过软链接执行到python2.7的。 ``` [root@localhost python-3.7]# python -V Python 2.7.5 [root@localhost python-3.7]# which python /usr/bin/python [root@localhost python-3.7]# ll /usr/bin/ |grep python -rwxr-xr-x. 1 root root 11216 Dec 1 2015 abrt-action-analyze-python lrwxrwxrwx. 1 root root 7 Sep 29 08:08 python -> python2 lrwxrwxrwx. 1 root root 9 Sep 29 08:08 python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Nov 19 2015 python2.7 [root@localhost python-3.7]# ``` 那我们也可以做一个软链接指向到python3命令 ``` [root@localhost python-3.7]# rm -rf /usr/bin/python [root@localhost python-3.7]# ln -s /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python [root@localhost python-3.7]# ll /usr/bin |grep python -rwxr-xr-x. 1 root root 11216 Dec 1 2015 abrt-action-analyze-python lrwxrwxrwx 1 root root 38 Sep 30 09:49 python -> /usr/local/sbin/python-3.7/bin/python3 lrwxrwxrwx. 1 root root 9 Sep 29 08:08 python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Nov 19 2015 python2.7 ``` 现在python的默认版本就是python 3.7.0了。 ``` [root@localhost python-3.7]# python -V Python 3.7.0 [root@localhost python-3.7]# python Python 3.7.0 (default, Sep 30 2018, 09:36:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ``` 修改完python的默认版本后,会存在一个问题,无法执行yum命令,修改yum命令文件,将头文件改为python2.7即可。 ``` [root@localhost python-3.7]# vim /usr/bin/yum #!/usr/bin/python2.7 #将头文件改为python2.7 ``` 同样的,将pip也指向到python3.7。 ``` [root@localhost python-3.7]# ln -s /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip [root@localhost python-3.7]# pip --version pip 10.0.1 from /usr/local/sbin/python-3.7/lib/python3.7/site-packages/pip (python 3.7) ```