由于mac使用到期,公司给还了新的mac,安装时安装了Anaconda(for 3.6+), Python 2.7慢慢没人维护了,是时候开始切换到3.6+上了。但是很尴尬的是,有些不再维护的库,却依然只支持python2.7,搞得很湿头痛,后来在网上查了资料,发现用conda是可以做到的。

conda

condaAnaconda的工具箱,它是 pip 和 vitualenv 的组合,也就是说他可以像pip来管理包,也可以像vitualenv来切换环境

切换Python2.x和Python3.x

那么怎么切换Python2.x和Python3.x呢。

1
2
3
4
5
6
7
8
9
10
11
12
# 基于 python3.6 创建一个名为test_py3 的环境
conda create --name test_py3 python=3.6

# 基于 python2.7 创建一个名为test_py2 的环境
conda create --name test_py2 python=2.7

# 激活 test 环境
activate test_py2 # windows
source activate test_py2 # linux/mac

# 切换到python3
source test_py3

在mac下只要能source test_py2或者source test_py3做到只有切换

conda安装包

1
2
3
4
5
6
7
8
9
10
11
12

# 安装 matplotlib
conda install matplotlib
# 查看已安装的包
conda list
# 包更新
conda update matplotlib
# 删除包
conda remove matplotlib

# 搜索
conda search flask

配置高速下载

打开我们的~/.condarc文件,配置如下

1
2
3
4
5
6
 channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
ssl_verify: true
~