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
    yum install gcc-c++ -y
    yum install openssl-devel -y
    
  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. 编译安装

    #进入Python-3.6.5目录
    cd Python-3.6.5
    
    #配置安装路径
    ./configure --prefix=/usr/local/python3 --enable-shared --with-ssl
    
    #安装
    make && make install
    

    如果报错make: *** 没有指明目标并且找不到 makefile。 停止。或者是英文的,解决办法:
    安装依赖包,然后从配置安装路径重新开始:

    yum install gcc-c++ -y
    yum install openssl-devel -y
    
  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. 将libpython3.6m.so.1.0 拷贝到/usr/lib64/下(此步骤非必须,如果下一步验证Python3是否安装报错则执行这步)

    cd /usr/local/python36/lib/
    cp libpython3.6m.so.1.0 /usr/lib64/
    
  9. 检查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)
    
posted @ 2019-07-26 09:46  程序猿杂记  阅读(117)  评论(0)    收藏  举报