参考资料:
conda -h
清华大学镜像站
指令格式
usage: conda [-h] [-V] command ...
usage: conda clean [-h] [-y] [--dry-run] [--json] [--debug] [--verbose] [-q] [-a] [-i] [-l] [-t] [-p] [-s]
usage: conda config [-h] [--json] [--debug] [--verbose] [--system | --env | --file FILE]
usage: conda create [-h] [-y] [--dry-run] [-f] [--file FILE] [--no-deps]
[--only-deps] [-m] [-C] [--use-local] [--offline]
[--no-pin] [-c CHANNEL] [--override-channels]
[-n ENVIRONMENT | -p PATH] [-q] [--copy] [-k]
[--update-dependencies] [--no-update-dependencies]
[--channel-priority] [--no-channel-priority] [--clobber]
[--show-channel-urls] [--no-show-channel-urls]
[--download-only] [--json] [--debug] [--verbose]
[--clone ENV] [--no-default-packages]
[package_spec [package_spec ...]]
usage: conda info [-h] [--json] [--debug] [--verbose] [--offline] [-a] [-e]
[-l] [-s] [--base] [--unsafe-channels]
[packages [packages ...]]
......
简介
Anaconda提供一种比普通python虚拟环境更加强大的支持,可以选择python版本,强大的包管理;并且对数据科学更加的支持。使用虚拟环境更加方便,并不需要进入相关的目录。
一些选项
1. 管理conda
1.1查看conda版本
conda --version
conda -V
输出如下:
conda 4.5.11
1.2 查看conda详细信息
conda info
输出如下
active environment : base
active env location : /home/lee/anaconda3
shell level : 1
(使用的config文件)user config file : /home/lee/.condarc
populated config files :
(conda版本)conda version : 4.5.11
conda-build version : 3.15.1
(python版本)python version : 3.7.0.final.0
(路径相关)base environment : /home/lee/anaconda3)
(使用的channels)
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/linux-64
https://repo.anaconda.com/pkgs/pro/noarch
package cache : /home/lee/anaconda3/pkgs
/home/lee/.conda/pkgs
(虚拟环境文件夹)envs directories : /home/lee/anaconda3/envs
/home/lee/.conda/envs
platform : linux-64
user-agent : conda/4.5.11 requests/2.19.1 CPython/3.7.0 Linux/4.15.0-46-generic ubuntu/16.04 glibc/2.27
UID:GID : 1000:1000
netrc file : None
offline mode : False
1.3 添加conda的国内源
使用清华源.
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
使用conda三方源
1.Conda Forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
2.msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
3.bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
4.menpo
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
5.pytorch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
1.4 更新conda
conda update
将conda包更新为最新的兼容版本。为此,它可能会更新一些已经安装的软件包,或者安装其他软件包。
--no update deps 防止现有包更新
--force 完全跳过依赖性检查
但是有时候,做了一些错误的指令,使得文件权限出现问题,我们可以使用最初的下载文件执行.(不会删除已有文件)
./Anaconda3-5.3.1-Linux-x86_64.sh -u
2.管理虚拟环境
2.1 帮助信息
输入如下指令可以查看环境管理的全部命令帮助:
conda env -h
2.2 创建环境
- 指定环境的名称(-n选项)
conda create -n env_name
或者
conda create --name env_name
输出如下:
Solving environment: done
(关于更新)
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 4.6.8
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
(文件的路径)
environment location: /home/lee/anaconda3/envs/lee
(确认执行)
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#(激活虚拟环境)
# $ conda activate lee
#
# To deactivate an active environment, use
#(退出虚拟环境)
# $ conda deactivate
- 指定python版本(python选项)
conda create -n lee_py36 python=3.6
输出如下:(要下载的东西更加多)
- 指定虚拟环境的路径
-p与-n参数不能同时使用
conda create -p /home/lee/lee_py36 python=3.6
2.3 查看现有环境
conda env list
2.4 删除环境
conda remove -n env_name --all
2.5 复制环境
conda create -n new_env --clone old_env
2.6 激活环境:
conda activate env_name
2.7 退出环境:
conda deactivate
3.安装python包:(同pip)
3.1 安装python包文件
conda install pypi_package
3.2 删除python包文件
conda remove pypi_package
3.3 列出目前的包文件
conda list