【Python3】Centos7 安装Python3.7

如果电脑自带的python2.7 先卸载
1.强制删除已安装python及其关联

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps

2.删除残余文件

whereis python|xargs rm -frv

开始安装pyton3

1.安装编译 以及 相关的工具

yum -y groupinstall "Development tools"

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

yum install libffi-devel -y

2.下载安装包解压

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar -xvJf  Python-3.7.0.tar.xz

3.编译安装

[root]# tar xvf Python-3.7.0.tar.xz

[root]# mv Python-3.7.0 /usr/local/python-3.7

[root]# cd /usr/local/python-3.7/

# 将python3.7安装到/usr/local/sbin/python-3.7目录下
[root python-3.7]# ./configure --prefix=/usr/local/sbin/python-3.7

[root python-3.7]# make && make install

4 安装成功之后使用

[root python-3.7]# /usr/local/sbin/python-3.7/bin/python3
Python 3.7.0 (default, Mar 15 2019, 00:44:37) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>exit

5.查看python命令的绝对路径

[root@python3 ~]# which python
/usr/bin/python

6 .创建软连接 以及环境变量

ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python3
ln -s /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip3

查看结果:

ll /usr/bin/ |grep python


可以看到 python指向了2.7版本,python 指向了3.7版本

创建环境变量

export PATH=$PATH:/usr/local/sbin/python-3.7/bin

7 验证是否成功

python3 -V
pip3 -V
# 卸载python3
rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps
# 删除残留文件
whereis python3 |xargs rm -frv
#查看现有安装的python
whereis   python      
posted @ 2020-03-02 16:14  依然范儿特西  阅读(1290)  评论(1编辑  收藏  举报