通过官网的方式下载Anaconda速度太慢,可以通过清华镜像源来下载:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
conda环境管理
显示虚拟环境列表
conda env list
创建一个名为xxx,python版本为x.x的虚拟环境(所有安装的环境会在anaconda/envs目录下)
conda create -n xxx python=x.x
进入虚拟环境
activate xxx # for Windows
conda activate xxx # for Linux & Mac
退出虚拟环境
deactivate xxx # for Windows
source deactivate xxx # for Linux & Mac
删除一个已有的环境
conda remove --name xxx --all
修改一个环境的名字(先用新名字克隆,再删除旧环境)
conda create --name new_name --clone old_name
conda remove --name old_name --all
conda包管理
显示anaconda安装的包
conda list
查看某个环境下的已安装包
conda list -n xxx
安装包
conda install numpy
可以通过-n来指定安装到哪个环境下(同理删除和更新库也一样)
conda install -n xxx numpy
可以通过-c来指定用哪个镜像源,如清华镜像源或者conda-forge
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ numpy
conda install -c conda-forge numpy
更新包
conda update numpy
删除包
conda remove numpy
更新conda
conda update conda
conda其他命令
通过直接输入conda可以查看所有的命令,包括:
clean、config、create、help、info、init、install、list、package、remove、uninstall、run、search、update、upgrade。
每个对应的命令可通过加入-h
或者--help
参数来查看该命令的功能和可选参数,如:
conda install -h
conda设置镜像源
由于Anaconda的服务器在国外,所以就会导致在国内下载一些库时会很慢,这时可以通过添加清华的镜像源来解决,并设置搜索时显示通道地址。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
执行完上面的操作,在Windows下的C:\Users\USER_NAME\目录中会生成.condarc文件,直接手动编辑这个文件也可以实现对镜像源的编辑。
查看所有镜像源
conda config --show-sources
conda config --get channels
查看配置,可通过channel查看已配置的镜像源
conda config --show
或者通过列出当前的配置信息来查看已配置的镜像源
conda info
删除某个镜像
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
换回默认源
conda config --remove-key channels
配置其他源
conda config --add channels r # R软件包
conda config --add channels conda-forge # conda社区维护的不在默认通道中的软件