zoukankan      html  css  js  c++  java
  • centos7中python2.7升级到python3.7

    一、下载源码包

    # 切换到root目录
    [root@localhost ~] cd /root/
    
    # 安装wget
    [root@localhost ~] yum -y install wget
    
    # 使用wget下载到目录
    [root@localhost ~] wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
    
    # 解压
    [root@localhost ~] tar xvf Python-3.7.0.tar.xz
    

    二、安装依赖

    [root@localhost ~] yum install gcc openssl-devel bzip2-devel expat-devel gdbm-devel sqlite-devel libffi-devel
    

    三、编译安装

    # 切换到解压后的目录Python-3.7.0
    [root@localhost ~] cd Python-3.7.0
    
    # 编译
    [root@localhost Python-3.7.0] ./configure --prefix=/usr/local/python3.7 --enable-shared CFLAGS=-fPIC
    
    # 生成安装文件,进行安装
    [root@localhost Python-3.7.0] make && make install
    

    四、配置环境

    # 备份python软连接,pip如果不存在就不用备份
    [root@localhost Python-3.7.0] mv -i /usr/bin/python /usr/bin/python.bak
    [root@localhost Python-3.7.0] mv -i /usr/bin/pip /usr/bin/pip.bak
    
    # 创建python3的连接
    [root@localhost Python-3.7.0] ln -sv /usr/local/python3.7/bin/python3 /usr/bin/python
    [root@localhost Python-3.7.0] ln -sv /usr/local/python3.7/bin/pip3 /usr/bin/pip
    
    # 配置动态库
    [root@localhost Python-3.7.0] vim /etc/ld.so.conf.d/python.conf
    # 写入内容
    /usr/local/python3.7/lib
    # 启用配置
    [root@localhost Python-3.7.0] ldconfig
    

    五、解决yum和防火墙问题

    # 修改下面几个文件内容的第一行的python为python2.7
    [root@localhost Python-3.7.0] vim /usr/libexec/urlgrabber-ext-down
    [root@localhost Python-3.7.0] vim /usr/bin/yum
    [root@localhost Python-3.7.0] vim /usr/bin/firewall-cmd
    [root@localhost Python-3.7.0] vim /usr/bin/firewall-offline-cmd
    [root@localhost Python-3.7.0] vim /usr/sbin/firewalld
    
    # 验证yum
    [root@localhost Python-3.7.0] yum list
    # 验证firewall
    [root@localhost Python-3.7.0] systemctl status firewalld.service
    

    六、修改pip源为阿里云

    # 创建配置文件pip.conf
    [root@localhost Python-3.7.0] cd /root/ && mkdir .pip && cd .pip && touch pip.conf
    
    #把下列内容写入到pip.conf文件
    [global]
    index-url = https://mirrors.aliyun.com/pypi/simple/
    [install]
    trusted-host=mirrors.aliyun.com
    
    # 更新pip到最新版
    [root@localhost Python-3.7.0] pip install --upgrade pip
    

    七、校验、删除

    # 命令行输入python,即可查看到版本号,如果还是2.7之类的就是没成功
    [root@localhost Python-3.7.0] python
    Python 3.7.0 (default, Jan 21 2020, 09:22:18) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    
    # python命令下,按住Ctrl+D退出
    [root@localhost Python-3.7.0] cd /root/
    
    # 删除解压文件和安装包,如果需要也可以不删除
    [root@localhost ~] rm -rf Python-3.7.0 Python-3.7.0.tar.xz
    
  • 相关阅读:
    mysql 7.5.8 服务无法启动 服务没有报告任何错误
    Ubuntu 16.04 php卸载
    函数式编程(3)-匿名函数
    函数式编程(2)-返回函数
    函数式编程(1)-高阶变成(3)-sorted
    函数式编程(1)-高阶变成(2)-filter
    函数式编程(1)-高阶变成(1)-map/reduce
    高级特性(4)-生成器
    高级特性(3)-列表生成式
    高级特性(2)-迭代
  • 原文地址:https://www.cnblogs.com/lixingwu/p/12205388.html
Copyright © 2011-2022 走看看