• python3 编译安装


    前言:

      Linux下大部分系统默认自带python2.x的版本,最常见的是python2.6或python2.7版本,默认的python被系统很多程序所依赖,比如centos下的yum就是python2写的,所以默认版本不要轻易删除,否则会有一些问题,如果需要使用最新的Python3那么我们可以编译安装源码包到独立目录,这和系统默认环境之间是没有任何影响的,python3和python2两个环境并存即可

      预处理

    [root@python ~]# python -V        //查看自带版本
    Python 2.7.5
    [root@python ~]# mkdir python3
    [root@python ~]# cd python3/
    
    [root@python ~]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz        //目前最新版本 

      准备好python的源码包,接下来准备编译安装所需的依赖包;

    [root@python ~]# yum -y install zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel
    [root@python ~]# yum install libffi-devel -y

       编译前预设

    [root@python ~]# cd python3/Python-3.7.2/
    [root@python Python-3.7.2]# pwd
    /root/python3/Python-3.7.2
    [root@python Python-3.7.2]# ls
    aclocal.m4           Doc         m4               Parser         README.rst
    CODE_OF_CONDUCT.rst  Grammar     Mac              PC             setup.py
    config.guess         Include     Makefile.pre.in  PCbuild        Tools
    config.sub           install-sh  Misc             Programs
    configure            Lib         Modules          pyconfig.h.in
    configure.ac         LICENSE     Objects          Python
    [root@python Python-3.7.2]# sed -ri 's/^#readline/readline/' Modules/Setup.dist
    [root@python Python-3.7.2]# sed -ri 's/^#(SSL=)/1/' Modules/Setup.dist
    [root@python Python-3.7.2]# sed -ri 's/^#(_ssl)/1/' Modules/Setup.dist
    [root@python Python-3.7.2]# sed -ri 's/^#([	]*-DUSE)/1/' Modules/Setup.dist
    [root@python Python-3.7.2]# sed -ri 's/^#([	]*-L$(SSL))/1/' Modules/Setup.dist

      设置完成,进行编译前的配置

    [root@python Python-3.7.2]# ./configure  --prefix=/usr/python
    
    //看到以下结果
    configure: creating ./config.status
    config.status: creating Makefile.pre
    config.status: creating Misc/python.pc
    config.status: creating Misc/python-config.sh
    config.status: creating Modules/ld_so_aix
    config.status: creating pyconfig.h
    creating Modules/Setup
    creating Modules/Setup.local
    creating Makefile
    
    //这个可以忽略,不会影响后面的安装
    If you want a release build with all stable optimizations active (PGO, etc),
    please run ./configure --enable-optimizations

      开始编译

    [root@python Python-3.7.2]# make -j 4
    
    [root@python Python-3.7.2]# make install
    //执行最后有以下
    Collecting setuptools
    Collecting pip
    Installing collected packages: setuptools, pip
    Successfully installed pip-18.1 setuptools-40.6.2

      编译安装完成

    [root@python Python-3.7.2]# ln -s /usr//python/bin/python3 /usr/bin/python3
    [root@python Python-3.7.2]# which python3
    /bin/python3
    [root@python Python-3.7.2]# python3 -V
    Python 3.7.2

    pip 安装

    [root@python Python-3.7.2]# cd ..
    [root@python python3]# ls
    Python-3.7.2  Python-3.7.2.tgz
    [root@python python3]# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

    python3 绑定pip

    [root@python python3]# python3 get-pip.py        //使用哪个python版本,pip就会绑定在哪个版本

    完成安装

    [root@python ~]# ln -s /usr/python/bin/pip3 /usr/bin/pip3
    
    [root@python ~]# which pip3
    /bin/pip3
    [root@python ~]# pip3 -V
    pip 19.0.3 from /usr/python/lib/python3.7/site-packages/pip (python 3.7)
    [root@python ~]#

     

  • 相关阅读:
    nginx
    spring 学习
    mysql 免安装 操作
    院感干预 报错
    iis 无法绑定 net.tcp
    wangEditor 自定义 菜单
    院感干预 发布
    第17篇 shell编程基础(2)
    第16篇 Shell脚本基础(一)
    第15篇 PSR-04 规范
  • 原文地址:https://www.cnblogs.com/sky-k/p/10523569.html
Copyright © 2020-2023  润新知