zoukankan      html  css  js  c++  java
  • linux系统安装Python 3.7.x

     1. 基础环境。

    [root@monitor ~]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core) 
    

     2. 升级openssl。CentOS 7.6默认自带的openssl是1.0.2,需要升级到1.1.1,否则使用pip安装模块是会报错“pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available”。(如果是先装的Python,后升级的openssl,则升级完后需要重新编译Python)

    [root@monitor ~]# openssl version
    OpenSSL 1.0.2k-fips  26 Jan 2017
    # 安装依赖。如果是CentOS 6.x的系统需要安装xz,否则下面解压Python压缩包会报错。
    [root@monitor ~]# yum -y install gcc xz
    # 下载新版本的openssl
    [root@monitor ~]# cd /usr/local/src
    [root@monitor src]# wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
    [root@monitor src]# tar xf openssl-1.1.1c.tar.gz
    [root@monitor src]# cd openssl-1.1.1c/
    [root@monitor openssl-1.1.1c]# ./config --prefix=/usr/local/openssl
    [root@monitor openssl-1.1.1c]# make
    [root@monitor openssl-1.1.1c]# make install
    # 备份原来的openssl,并为新版本的openssl创建软链接。
    [root@monitor openssl-1.1.1c]# mv /usr/bin/openssl{,.bak}
    [root@monitor openssl-1.1.1c]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
    [root@monitor openssl-1.1.1c]# ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
    [root@monitor openssl-1.1.1c]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
    # 写入openssl库文件的搜索路径,并使之生效。
    [root@monitor openssl-1.1.1c]# echo "/usr/local/openssl/lib" >>/etc/ld.so.conf
    [root@monitor openssl-1.1.1c]# ldconfig -v
    [root@monitor openssl-1.1.1c]# openssl version
    OpenSSL 1.1.1c  28 May 2019
    

     3. 下载Python 3.7.x的tar包,并解压。

    [root@monitor openssl-1.1.1c]# cd /usr/local/src/
    [root@monitor src]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
    [root@monitor src]# tar xf Python-3.7.2.tar.xz
    [root@monitor src]# cd Python-3.7.2/
    

     4. 编译安装。

    # 安装依赖包。
    [root@monitor Python-3.7.2]# yum -y install zlib-devel libffi-devel
    [root@monitor Python-3.7.2]# ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
    [root@monitor Python-3.7.2]# make && make install
    Successfully installed pip-18.1 setuptools-40.6.2
    

     5. 配置环境变量。

    [root@monitor python3]# cd /usr/local/python3/bin/
    [root@monitor bin]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    [root@monitor bin]# echo 'export PATH=/usr/local/python3/bin/:$PATH' >>/etc/profile
    [root@monitor bin]# . /etc/profile
    [root@monitor bin]# python3 -V
    Python 3.7.2
    

     6. 测试pip安装requests模块。

    [root@monitor bin]# pip3 install requests
    Successfully installed certifi-2019.6.16 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.3
    


    写作不易,转载请注明出处,谢谢~~

  • 相关阅读:
    Java Spring Boot VS .NetCore (十) Java Interceptor vs .NetCore Interceptor
    Java Spring Boot VS .NetCore (九) Spring Security vs .NetCore Security
    IdentityServer4 And AspNetCore.Identity Get AccessToken 问题
    Java Spring Boot VS .NetCore (八) Java 注解 vs .NetCore Attribute
    Java Spring Boot VS .NetCore (七) 配置文件
    Java Spring Boot VS .NetCore (六) UI thymeleaf vs cshtml
    Java Spring Boot VS .NetCore (五)MyBatis vs EFCore
    Java Spring Boot VS .NetCore (四)数据库操作 Spring Data JPA vs EFCore
    Java Spring Boot VS .NetCore (三)Ioc容器处理
    Java Spring Boot VS .NetCore (二)实现一个过滤器Filter
  • 原文地址:https://www.cnblogs.com/ccbloom/p/11478056.html
Copyright © 2011-2022 走看看