centos7.8安装python3.12.3

centos7.8安装python3.12.3

码农世界 2024-05-23 前端 64 次浏览 0个评论

文章目录

  • 环境准备
    • 1 安装依赖项
    • python源码准备
    • 编译
    • 验证
    • 配置环境变量(可选)

      环境准备

      1 安装依赖项

      sudo yum update -y
      sudo yum groupinstall -y "Development Tools"
      sudo yum install -y \
          gcc \
          openssl-devel \
          bzip2-devel \
          libffi-devel \
          zlib-devel \
          wget
      sudo yum install -y centos-release-scl
      sudo yum install -y devtoolset-10
      scl enable devtoolset-10 bash
      echo "source /opt/rh/devtoolset-10/enable" >> ~/.bashrc
      source ~/.bashrc
      

      python源码准备

      cd /usr/src
      sudo wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
      sudo tar xzf Python-3.12.3.tgz
      cd Python-3.12.3
      

      编译

      sudo mkdir -p /data/opt/python/python3
      sudo ./configure --prefix=/data/opt/python/python3 --enable-optimizations
      sudo make altinstall
      wget https://bootstrap.pypa.io/get-pip.py
      sudo /data/opt/python/python3/bin/python3.12 get-pip.py
      

      验证

      /data/opt/python/python3/bin/python3.12 --version
      /data/opt/python/python3/bin/pip3.12 --version
      

      配置环境变量(可选)

      sudo vim /etc/profile
      # Set PATH for Python 3.12 installation
      export PATH="/usr/local/bin/python3.12:$PATH"
      # 保存并关闭文件,然后使更改生效:
      source /etc/profile
      ln -s xxx xxx
      

转载请注明来自码农世界,本文标题:《centos7.8安装python3.12.3》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,64人围观)参与讨论

还没有评论,来说两句吧...

Top