zoukankan      html  css  js  c++  java
  • centos6安装Python3环境

    Python3安装

    CentOS 6+系统默认安装的python版本是2.6.6,python2版本与python3还有有一些语法上的不一样。我们要把python升级到3版本,但是系统自带的旧版本python被系统很多其他软件环境依赖,所以不能直接卸载原来的2版本,所以我们重新安装一个3版本,将2版本的依赖保留。


    1、下载Python安装包

    源码包下载地址:https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz


    2、安装源码编译器等工具:

    [root@bigdata-pro03 softwares]# yum -y install gcc gcc-c++ autoconf automake make zlib zlib-devel

    3、解压下好的源码包:

    [root@bigdata-pro03 softwares]# tar -xzvf Python-3.6.0.tgz
    [root@bigdata-pro03 softwares]# cd /opt/modules/Python-3.6.0/
    [root@bigdata-pro03 Python-3.6.0]# ls
    aclocal.m4    configure     Grammar     Lib      Makefile.pre.in  Objects  PCbuild        Python    Tools
    config.guess  configure.ac  Include     LICENSE  Misc             Parser   Programs       README
    config.sub    Doc           install-sh  Mac      Modules          PC       pyconfig.h.in  setup.py

    4、编译安装包,指定安装路径:


    注意:prefix参数用于指定将Python安装在新目录,这样不会覆盖原有的python。

    ./configure --prefix=/usr/local/python36   
    make && make install

    5、修改系统默认的Python路径,因为默认的python指向2.6

    mv /usr/bin/python /usr/bin/python-2.6.6  

    6、建立新的软连接,指向Python-3.6.0:


    注:这里的python36是第4步指定的安装路径,python3.6是Python包里的可执行程序

    ln -s /usr/local/python36/bin/python3.6 /usr/bin/python

    7、因为yum是依赖python的,所以这里我们修改了默认的python,就要要修改yum,让其运行指向旧的版本:

    vim /usr/bin/yum
    
    将第一行“#!/usr/bin/python”
    
    修改为“#!/usr/bin/python-2.6.6

    8、测试按是否安装成功

    [root@bigdata-pro02 Python-3.6.0]# python
    Python 3.6.0 (default, Nov 16 2019, 09:39:23) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 

    可以看到,已经成功安装Python3.6.0!

    pip3安装

    1、下载安装文件,使用python命令进行安装

    wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
    python get-pip.py


    2、为pip建立软连接,使用pip命令安装requests模块

    ln -s /usr/local/python36/bin/pip3.6 /usr/bin/pip
    pip -V
    pip install requests
    [root@bigdata-pro03 gcc-build-9.2.0]# pip
    
    Usage:   
      pip <command> [options]
    
    Commands:
      install                     Install packages.
      download                    Download packages.
      uninstall                   Uninstall packages.
      freeze                      Output installed packages in requirements format.
      list                        List installed packages.
      show                        Show information about installed packages.
      check                       Verify installed packages have compatible dependencies.
      config                      Manage local and global configuration.
      search                      Search PyPI for packages.
      wheel                       Build wheels from your requirements.
      hash                        Compute hashes of package archives.
      completion                  A helper command used for command completion.
      debug                       Show information useful for debugging.
      help                        Show help for commands.
    
    General Options:
      -h, --help                  Show help.
      --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
      -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
      -V, --version               Show version and exit.
      -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR,
                                  and CRITICAL logging levels).
      --log <path>                Path to a verbose appending log.
      --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
      --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
      --timeout <sec>             Set the socket timeout (default 15 seconds).
      --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
      --trusted-host <hostname>   Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
      --cert <path>               Path to alternate CA bundle.
      --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM
                                  format.
      --cache-dir <dir>           Store the cache data in <dir>.
      --no-cache-dir              Disable the cache.
      --disable-pip-version-check
                                  Don't periodically check PyPI to determine whether a new version of pip is available for download.
                                  Implied with --no-index.
      --no-color                  Suppress colored output

    到此,Centos系统下的Python3环境就搭建完成了!

  • 相关阅读:
    分分钟用上C#中的委托和事件
    AutoResetEvent详解
    C#跨线程调用
    多线程编程的注意事项
    C#中WinForm程序退出方法技巧总结
    用c#实现单链表(程序代码已经验证,完全正确)
    event & EventHandler
    Kubernetes理论02
    centos7 日志文件
    CentOS7 FTP安装与配置
  • 原文地址:https://www.cnblogs.com/zimo-jing/p/11873413.html
Copyright © 2011-2022 走看看