阿里云Linux下python3的安装及环境配置(详细教程)

文章目录

    • 一、yum安装依赖
    • 二、下载安装
    • 三、加入command
    • 四、更换国内镜像
    • 五、备注

一、yum安装依赖

  1. 由于yum需要 linux系统自带python2.7.5
  2. yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel xz-devel
  3. yum list installed |grep 包名 查看依赖安装情况

二、下载安装

  1. cd /home/test/python
  2. wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
  3. tar –xvzf Python-3.7.5.tgz && cd Python-3.7.5
  4. ./configure --prefix=/usr/local/python3 指定安装路径
  5. make && make install

三、加入command

  1. ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
  2. ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
    在这里插入图片描述

四、更换国内镜像

  1. 创建~/.pip/pip.conf,加入
[global]
timeout = 6000
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
  1. 再次下载安装时即可查看镜像地址
    在这里插入图片描述

五、备注

       pthon3执行python脚本时出现Could not import the lzma module.错误需要以下操作

  1. yum install xz-devel python-backports-lzma
  2. pip3 install backports.lzma
  3. 在/usr/local/python3/lib/python3.7/lzma.py 27行修改成下面
import builtins
import io
import os
#from _lzma import *
#from _lzma import _encode_filter_properties, _decode_filter_properties
try:
    from _lzma import *
    from _lzma import _encode_filter_properties, _decode_filter_properties
except ImportError:
    from backports.lzma import *
    from backports.lzma import _encode_filter_properties, _decode_filter_properties
import _compression

你可能感兴趣的:(笔记)