python 环境安装

Ubuntu安装

以下是以 Ubuntu 16.04 LTS 为例子演示安装情况

查看系统类型

1
lsb_release -a

你会看到以下信息系统内核 Codename:xenial, 系统版本 Release:16.04

设置 apt 源

(为了解决 apt-get 安装出现 E:unable to locate package 问题)

根据查看到到系统的版本的类型配置不同的源,在本例子中就配置如下(来源阿里云)

1
2
3
4
5
6
7
8
9
10
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

直接配置在/etc/apt/sources.list 就可以了
配置后执行

  • apt update
  • apt upgrade

安装 python pip

  • apt-get install -y python3-pip python3-dev
  • pip3 install –upgrade pip

Window 安装

安装python

  1. 根据系统的信息选择对应的包, 下载连接
    web-based installer 是需要通过联网完成安装的
    executable installer 是可执行文件(*.exe)方式安装
    embeddable zip file 嵌入式版本,可以集成到其它应用中
  2. 选择 executable installer 下载exe文件,一键安装

安装python编译的c++环境

  1. 安装c++ 环境, 下载visual studio installer

  2. 选择 Free, fully-featured IDE for students, open-source and individual developers第一个 free download

  3. 一键安装

  4. 选择c++ 环境如下图

python2 跟 python3 并存问题

Ubuntu 16.04 自带 python2 python3
运行

1
pip -V

查看到 pip from python3.x 就是是说明你 pip install 运行的环境是 python3.x 的,自此就可以愉快使用 python3 啦。
能用 python3 就用 3,python2 已经停止维护了。