0%

conda使用总结

清华源

官网:https://mirror.tuna.tsinghua.edu.cn/help/anaconda/

Ubuntu系统可以使用如下命令修改用户目录下的 .condarc 文件

1
sudo gedit ~/.condarc

将如下命令添加到文件中即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。

运行 conda create -n myenv numpy 测试一下吧。

创建环境

创建一个名为envirment_name的虚拟环境

1
conda create -n envirment_name

激活环境

1
conda activate envirment_name

安装包

安装3.6版本的python

1
conda install python==3.6

删除包

1
conda uninstall python

删除环境

删除envirment_name这个环境的所有内容,-n指定环境名,–all代表删除全部内容。

1
conda remove -n envirment_name --all

使用yml创建环境

conda可以通过config文件指定包的版本来创建环境,例如使用如下命令

1
conda env create --file environment.yml

其中environment.yml文件中的信息如下

1
2
3
4
5
6
7
8
9
10
11
12
13
name: envirment_name
channels:
- defaults
- conda-forge
- pytorch
dependencies: # everything under this, installed by conda
- python=3.6
- pip
- pytorch=1.2.0
- torchvision=0.4.0
- cudatoolkit=10.0
- pip: # everything under this, installed by pip
- open3d==0.8.0

清理conda无用的包和缓存

cache目录在/home/username/.conda/pkgs。可以使用-p来删除没有用到的包,想删除干净点就用-y –all来删除所有下载的包和缓存。想看更多选项可以-h看帮助文档。

1
2
3
conda clean -p      //删除没有用的包
conda clean -y -all //删除所有的安装包及cache
conda clean -i //删除索引缓存