CentOS7.9 安装python3.12

      解决configer报错:

        checking for openssl/ssl.h in /usr/local... no
        checking whether compiling and linking against OpenSSL works... no
        checking for --with-openssl-rpath... auto
        checking whether OpenSSL provides required ssl module APIs... no
        checking whether OpenSSL provides required hashlib module APIs... no
        checking for --with-ssl-default-suites... python

  1. 下载openssl1.1.1及以上版本并安装

       Release OpenSSL 1.1.1 · openssl/openssl · GitHub

        

        ./config --prefix=/usr/local/openssl shared zlib

        sudo make

        sudo make install 

        sudo ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl

         $ openssl version
         OpenSSL 1.1.1  11 Sep 2018 (Library: OpenSSL 1.1.1k  FIPS 25 Mar 2021)

         

        设置环境变量LD_LIBRARY_PATH

        echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib" >>         $HOME/.bash_profile
        source $HOME/.bash_profile   

  1. 安装依赖包:sudo yum -y install openssl11.x86_64 zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
  2. 下载Python源代码:wget https://www.python.org/ftp/python/3.x.x/Python-3.x.x.tgz

        将3.x.x替换为你想安装的Python版本号。

   

解压源代码:tar xvf Python-3.x.x.tgz

编译安装:

cd Python-3.x.x

sudo ./configure --with-openssl=/usr/local/openssl --with-openssl-rpath=auto

sudo make clean

sudo make

sudo make install

验证安装:

  python3.12 --version (3.12替换为你安装的Python版本号

                             

设置默认python版本:

  1. 打开终端并输入以下命令查看当前系统上所有已安装的Python版本

        ls /usr/bin/python*

        2、根据第二步得到的结果,选择要作为默认版本的Python 3.8对应的路径。假设该路径
        sudo ln -sf /usr/local/bin/python3.12 /usr/bin/python

        3、 查看当前python版本

        $ python -V
        Python 3.12.0

你可能感兴趣的:(linux,运维,服务器)