本人使用的几点说明安装版本为: Anaconda3-5.2.0-Linux-x86_64 且安装时选择不安装 Microsoft VSCode,安装后环境很健康,.bashrc文件没有以前那种十多行关于anaconda的设置
启动命令
anaconda-navigator
升级当前版本的conda
conda update 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 # 设置搜索时显示通道地址
# or 中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
删除Channels
conda config --get channels
conda config --remove channels
conda config --set show_channel_urls yes
设置超时时间
conda config --set remote_connect_timeout_secs 1800 # 连接超时
conda config --set remote_read_timeout_secs 3600 # 读取超时
<< 环境操作 >>Managing environmentsconda.io
列出所有环境
conda info --envs
检查环境中python版本
python --version
新建环境
conda create -n 环境名 python=3.7
激活环境
source activate 环境名
复制环境
conda create -n 新环境名 --clone 旧环境名
移除环境
conda remove -n 环境名 --all
保存和加载环境
conda info -e # 列出所有环境
conda activate env_name #激活要共享的环境
conda env export # 将要共享的环境信息输出到终端,便于检查
conda env export > ~/environment.yaml # 导出到文件environment.yaml
conda env create -f environment.yaml # 加载环境
注:不使用conda的用户,可以使用 pip freeze将一个 pip requirements.txt 文件导出并包括在其中,参见https://pip.pypa.io/en/stable/reference/pip_freeze/pip.pypa.io
跨平台迁移和直接整体迁移环境
cd ~/anaconda3/envs
zip -r file_name.zip env_name
unzip file_name.zip # anaconda3的指定位置
<< 管理包 >>
查看已安装包
conda list
# pip查看安装包
pip freeze 或者 $ pip list
使用conda安装包(建议参见别的教程,比如更换安装源,本方法较少使用)
conda install 包名字 # 后面可以加 =版本号
使用pip安装包(使用较多,清华源)
pip --default-timeout=3600 install -i https://pypi.tuna.tsinghua.edu.cn/simple torch torchvision
移除包
conda remove -n 环境名 安装包名
conda remove package_name #移除当前环境中的包
更新包(某个/全部)
conda update package_name
conda update --all
rm -rf ~/anaconda3
历史使用方法:
(可能用处不大,且pytorch安装直接参照官网即可)
1. 安装anaconda
bash Anaconda文件名.sh
2. 使用anaconda创建一个pytorch环境
conda create -n pytorch python=3.6
3. 修改conda镜像源(直接终端运行)
conda config --prepend 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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
查看是否已添加源
conda config --set show_channel_urls yes
cat ~/.condarc
4. 安装pytorch
conda install pytorch torchvision cpuonly
上面如果这条命令不好使,就允许如下代码
conda install pytorch-cpu torchvision-cpu
注:上述命令来自官网,讲 -c pytorch 已去掉,只有cpu的版本,不含 GPU
附注:有时候网络下载较慢,创建环境时,可能会因为python下载过慢而中断,可在~/.condarc文件中添加代码 remote_read_timeout_secs: 1800.0 来设定下载最大时间
ssl_verify: true
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
参考链接: