zoukankan      html  css  js  c++  java
  • 在linux上安装python

    转自:https://www.cnblogs.com/qq631243523/p/10191726.html

    一,前言

    centos7默认是装有python的,咱们先看一下

    [root@glh ~ 20:18:03]#python
    Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 

    默认自python2。

    但是python2在2020年就在更新了,所以我们要积极向python3转型。

    二,Centos7下安装python3

    1,下载python源码包

    https://www.python.org/ftp/python/  # 有各个版本
    这里我们下载python3.6.5版本
    https://www.python.org/ftp/python/3.6.5/
    下载.tar.xz结尾的
    https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz

    Centos下我们只需要执行wget 即可下载该源码包

    wget  https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz

    2,python依赖的环境,先装这些

    yum install gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y

    3,解压安装源码包

    wget https://www.python.org/ftp/python/3.4.7/Python-3.4.7.tar.xz
    xz -d Python-3.4.7.tar.xz
    tar -xf Python-3.4.7.tar
    复制代码
    cd到解压之后的Python-3.6.5之下,执行
    
    ./configure --prefix=/opt/python3.6.5
    
    然后执行
    make && make install
    复制代码
    复制代码
    1、./configure 是用来检测你的安装平台的目标特征的。比如它会检测你是不是有CC或GCC,并不是需要CC或GCC,它是个shell脚本。
    
    2、make 是用来编译的,它从Makefile中读取指令,然后编译。
    
    3、make install是用来安装的,它也从Makefile中读取指令,安装到指定的位置。
    复制代码

    4,添加环境变量

    [root@glh ~ 20:22:33]#vim /etc/profile
    # 在文件的最后一行配置PATH
    PATH=/opt/python3.6.5/bin:$PATH  # 这个/opt/python3.6.5/bin就是刚才安装的python3.6.5的路径
    :wq! 保存退出
    source /etc/profile 执行这句话让PATH生效

    也可以采用软连接的方式

    ln -s /opt/python3.6.5/bin python3  usr/bin/python3

    5,检查是否安装成功

    [root@glh ~ 20:36:50]#python3  输入python3显示下面信息即表示安装成功
    Python 3.6.5 (default, Nov 12 2018, 17:50:12) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
  • 相关阅读:
    使用jquery-qrcode生成二维码
    ASP.NET匿名对象与集合的使用
    ASP.NET Core 之跨平台的实时性能监控
    centos7如何将docker容器配置成开机自启动
    linux 查看系统信息命令
    基于.NET CORE微服务框架 -浅析如何使用surging
    Docker 两键创建 ZeroTier moon 节点
    kubernetes-dashboard获取令牌登陆
    docker环境下使用gitlab,gitlab-runner 为 NetCore 持续集成
    Docker For MYSQL 8.0 特别注意修复数据库新的验证方式
  • 原文地址:https://www.cnblogs.com/qq849784670/p/10192744.html
Copyright © 2011-2022 走看看