Anaconda安装、配置国内镜像源(pip & conda),conda环境创建、移植

下载地址

官网下载
清华镜像

安装并进入base环境

windows

浏览器下载

直接运行Anaconda-...-Windows-*.exe
左下角搜索Anaconda,打开Anaconda的dos界面,自动进入base环境

linux

下载
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.11-Linux-x86_64.sh
安装
bash Anaconda3-2020.11-Linux-x86_64.sh
自动配置环境处选择yes
安装好之后激活环境
source ~/.bashrc

进入base环境后,命令行左侧会显示(base)

配置国内镜像源

http://mirrors.aliyun.com/pypi/simple/ //阿里
https://pypi.tuna.tsinghua.edu.cn/simple/ //清华
http://pypi.douban.com/ //豆瓣
http://pypi.hustunique.com/ //华中理工大学
http://pypi.sdutlinux.org/ //山东理工大学
http://pypi.mirrors.ustc.edu.cn/ //中国科学技术大学

pip

mkdir ~/.pip
vim ~/.pip/pip.conf

将该文件配置为国内镜像源(例如豆瓣),修改最长等待时间

[global]
index-url = http://pypi.douban.com/simple
timeout=60000
[install]
trusted-host = pypi.douban.com

conda

添加镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
删除镜像源
conda config --remove-key channels
查看镜像源
conda config --show-sources
显示通道地址
conda config --set show_channel_urls yes

直接修改配置文件

vim ~/.condarc

channels:
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
 - defaults
show_channel_urls: true

其中defaults为默认国外源

创建沙箱

conda create -n name python=3.8#沙箱名,python版本
conda activate name激活环境

环境移植

可以同一台计算机内部拷贝或拷贝到其他计算机

联网环境拷贝

首先激活需要拷贝的环境,将环境拷贝到yaml文件(文件名可任意修改)

conda activate [env-name]
 conda env export > env.yaml

根据yaml文件复现环境

 conda env create -f env.yaml

offline环境拷贝

详细教程·传送门

进入*/anaconda3/envs/目录,将需要拷贝的环境打包

tar cvf envirement.tar envirement

envirement.tar文件通过http、ssh等方式拷贝到目标计算机*/anaconda3/envs/目录,解包

rsync -rzP */envirement.tar ~/anaconda3/envs
tar xvf envirement.tar

* : path of envirement.tar
最后修改conda的环境配置文件~/.conda/envirement.txt,在尾部添加拷贝的环境目录
vim ~/.conda/envirement.txt

/root/anaconda3
/root/anaconda3/envs/envirement

猜你喜欢

转载自blog.csdn.net/qq_38832757/article/details/112878865