linux 安装 python3

  • python3的依赖环境,一般不需要安装(我没安装):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
  • cd /opt随便进入个目录
  • wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz下载对应版本
    • yum -y install wget安装wget,或者通过其他方法下载上传进去也可以
  • tar -zxvf Python-3.7.1.tgz解压
  • cd Python-3.7.1.tgz进入解压后的目录
  • yum install gcc安装gcc,确认下载安装输入y(我在安装的时候没看到需要输入)
  • yum install libffi-devel -y3.7版本之后需要一个新的包libffi-devel
  • mkdir -p /usr/local/python3创建python3安装目录,根据个人习惯喜好自选
  • ./configure --prefix=/usr/local/python3生成编译脚本(指定安装目录)
  • make编译
  • make install编译安装
  • /usr/local/python3/bin/python3.7检查python3.7的编译器
  • ln -s /usr/local/python3/bin/python3 /usr/bin/python3建立Python3的软链
  • ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3建立pip3的软链
  • /usr/local/python3/bin加入PATH
    • vim /etc/profile开始编辑,将下面的内容添加到最后
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      # 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
    • source ~/.bash_profile修改生效
  • python3 -V通过检查版本确认是否成功安装
  • pip3 -V通过检查版本确认是否成功安装