Centos7 安装python3.6(与python2.7共存)

  1. 安装相关依赖包(需要超级用户)
    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

  2. 使用wget从官网下载安装包(网址根据需求改变)
    wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz

  3. 解压安装包
    tar -xf Python-3.6.5.tar.xz

  4. 编译安装
    (1)进入Python-3.6.5目录
    cd Python-3.6.5
    (2)配置安装路径
    ./configure prefix=/usr/local/python3
    (3)安装
    make && make install

  5. 创建python3的软链接
    ln -s /usr/local/python3/bin/python3 /usr/bin/python3

  6. 将/home/lilei/python3/bin加入PATH
    执行命令:vim ~/.bash_profile

    # .bash_profile
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi
    # User specific environment and startup programs
    PATH=$PATH:$HOME/bin:/usr/local/python3/bin
    export PATH
    

    按i进行编辑
    按ESC,输入:wq,回车保存退出编辑

  7. 提交修改(让上边修改内容生效)
    source ~/.bash_profile

  8. 检查Python3 和 pip3 是否可以正常使用

      # python3 -V
      Python 3.6.5
      # pip3 -V
      pip 9.0.3 from /usr/local/Python3/lib/python3.6/site-packages (python 3.6)
    

你可能感兴趣的:(Python)