Centos 7安装使用Python

概述

Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。详见Python官网


安装

## 安装python3
yum install python3;

## 查看版本(无须将python升级到最新版,目前版本已跢使用)
python -V;

## 更新python3
yum update python3;

安装pip,pip用来管理python包

## 安装pip 
yum -y install python-pip
## 升级pip
pip3 install --upgrade pip

注:Centos7自带了python2,yum是基于python2写的,因此千万不要删除python2;


运行环境

要想运行python程序,可以使用python的交互解释运行环境,终端中直接输入 python 命令即可进入,输入 exit() 退出;


PIP3国内镜像(Linux/Mac)

Linux/Mac os 环境中,配置文件位置在 ~/.pip/pip.conf(如果不存在创建该目录和文件):

mkdir ~/.pip

打开配置文件 ~/.pip/pip.conf,修改如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

查看/验证 镜像地址:

$ pip3 config list   
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'


PIP3国内镜像(Windows)

Windows下,在当前对用户目录下(C:\Users\xx\pip)创建一个 pip.ini在pip.ini文件中输入以下内容:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn




Python基本使用


举报

© 著作权归作者所有


0