Env 创建
1 2 3
| conda create -n XXX python=3.8 conda create -n XXX --clone oldXXX conda remove -n oldXXX --all
|
修改环境名字
1 2 3 4 5 6
| 直接修改conda环境下的目录名即可
base /root/anaconda3 torch_1.4.0_cu100 /root/anaconda3/envs/torch_1.4.0_cu100 torch_1.4.1 /root/anaconda3/envs/torch_1.4.1
|
一、镜像
1.镜像源添加方法
首先是一些常用命令,帮你诊断目前你的conda源的情况,如果是新装的conda,可以不用管。
第一步:查看并还原默认镜像源
1.1 首先,看一下目前conda源都有哪些内容
conda info
1.2 然后,删除并恢复默认的conda源
1
| conda config --remove-key channels
|
下面是几个常用命令:后面会用到,这里不用管
1.3 添加指定源
1
| conda config --add channels *(*指代你要添加的源)
|
1.4 设置安装包时,显示镜像来源,建议显示
1
| conda config --set show_channel_urls yes
|
1.5 删除指定源
1
| conda config --remove channels *(*代表你要删除的源)
|
2.找到你要用的源
首先,我们进入国内几家镜像源的网站(这里以清华园为例,基本上可以涵盖所有镜像)
清华镜像源 一般够用 :https://mirrors.tuna.tsinghua.edu.cn/
中科大源https://mirrors.ustc.edu.cn/
常用的其他源汇总
1 2 3 4 5 6
| #为了方便大家快速添加,我们把conda自身默认的镜像源的替换代码,写好放在这里,方便大家直接替换使用,大家逐条复制添加即可,下述链接更新时间为2022.3.10,可以通过前面的方法先判断一下镜像源对不对: conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 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/r/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --set show_channel_urls yes
|
二、Conda Env环境(linux)
环境备份
1 2 3 4 5 6 7 8 9 10
| 路径:<user home>/.conda/envs/
导出环境备份: conda env export --name your_env_name > environment.yml
导出环境备份(批量): for env in $(conda env list | awk '{print $1}' | tail -n +3); do conda env export --name $env > ~/.conda/envs/$env.yml; done
重建环境 conda env create -f environment.yml
|
2.2 在Linux环境下修改Anaconda的默认虚拟环境安装位置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # 1 check conda info
package cache : /home/sxw/anaconda3/pkgs /home/sxw/.conda/pkgs envs directories : /home/sxw/anaconda3/envs /home/sxw/.conda/envs # 2 change conda config --add envs_dirs /home/username/Software/anaconda3/ or sudo vim ~/.condarc pkgs_dirs: - /dataraid/apps/appdata/pkgs envs_dirs: - /dataraid/apps/appdata/envs
# 4 check
|
Windows Env 配置
1 2 3 4 5 6 7 8 9 10 11 12
| channels: - https://mirrors.aliyun.com/anaconda/miniconda/ - defaults - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ - https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ - https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch/ ssl_verify: true envs_dirs: - D:\AppData\Anaconda\envs pkgs_dirs: - D:\AppData\Anaconda\pkgs
|
三、PIP镜像
1
| pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
1、永久使用pip源 此时,我们可以把源改为清华源,具体操作如下:
1
| pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
如果set多次,似乎只能保存最后一次set的镜像源。
2、临时更换pip源 如果仅是临时更换可以使用以下命令
1 2 3 4 5
| pip install -r requirement.txt pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple pip install torch -i http://mirrors.aliyun.com/pypi/simple/
此时,我们再用pip安装软件就会比较快了
|
3、查看pip源
pip config list
4、删除pip源
pip config unset global.index-url
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| [global] no-cache-dir = true # index-url = https://pypi.org/simple index-url = https://pypi.tuna.tsinghua.edu.cn/simple extra-index-url = https://pypi.ngc.nvidia.com trusted-host = mirrors.aliyun.com pypi.ngc.nvidia.com
[global] #index-url = http://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com pypi.ngc.nvidia.com no-cache-dir = true extra-index-url = https://pypi.ngc.nvidia.com
root@ubuntu8125:~# pip config list global.extra-index-url='\nhttps://pypi.ngc.nvidia.com' global.index-url='https://pypi.org/simple' global.no-cache-dir='true' global.trusted-host='\npypi.ngc.nvidia.com'
/etc/pip.conf
[global] no-cache-dir = true # index-url = https://pypi.org/simple index-url = http://mirrors.aliyun.com/pypi/simple/ extra-index-url = https://pypi.ngc.nvidia.com trusted-host = mirrors.aliyun.com pypi.ngc.nvidia.com
/root/.pip/pip.conf
/root/anaconda3/pip.conf
[global] #index-url = http://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com pypi.ngc.nvidia.com no-cache-dir = true extra-index-url = https://pypi.ngc.nvidia.com
|
Pip多个源头:
1 2 3 4 5 6 7 8
| no-cache-dir = true extra-index-url = https://pypi.ngc.nvidia.com https://mirrors.aliyun.com/pypi/simple trusted-host = pypi.ngc.nvidia.com mirrors.aliyun.com index-url = https://pypi.org/simple
|