目录

在Ubuntu上使用Conda

简介

Conda

Conda is an open source package management system and environment management system that runs on Windows, macOS and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads and switches between environments on your local computer. It was created for Python programs, but it can package and distribute software for any language.

Anaconda

A downloadable, free, open source, high-performance and optimized Python and R distribution. Anaconda includes conda, conda build, Python and 100+ automatically installed, open source scientific packages and their dependencies that have been tested to work well together, including SciPy, NumPy and many others. Use the conda install command to easily install 1,000+ popular open source packages for data science—including advanced and scientific analytics—from the Anaconda repository. Use the conda command to install thousands more open source packages.

Miniconda

Don’t want the huge collection of 720 software packages? Get Miniconda.

安装

首先下载安装脚本:

1
2
3
4
# Python3 64位机
https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
# Python3 32位机
https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86.sh

修改权限并运行:

1
2
chmod u+x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

安装完成后在~/.zshrc 中增加:

1
export PATH="/root/miniconda3/bin:$PATH"

配置

1
2
3
4
5
# 添加Anaconda的TUNA镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

环境管理

Conda的环境管理功能允许我们同时安装若干不同版本的Python,并自由切换。

创建环境。如果不指定版本,则默认使用安装的py版本:

1
conda create -n py35env python=3.5

查看已安装的环境。当前被激活的环境会有一个*或者()标识。

1
conda info -e

删除环境:

1
conda remove -n py35env --all

激活环境:

1
source activate py35env

退出环境:

1
source deactivate py35env

包管理

与pip类似。以下操作,不使用-n指定环境时操作到当前环境。

安装package

1
conda install -n py35env numpy

查看已安装的package

1
conda list -n py35env

更新package

1
conda update -n py35env numpy

删除package

1
conda remove -n py35env numpy

查找package信息(不需要也不能指定环境)

1
conda search numpy

卸载

1
2
rm -rf ~/miniconda
rm -rf ~/.condarc ~/.conda ~/.continuum

删除在.zshrc中增加的export行。