Conda 安装注记
1. 下载与安装
Python 科学计算库, 有两个发行版
- Anaconda
- Miniconda
推荐安装 Miniconda, 更加轻量级, 所有的安装都可控. 一般初学者可以使用完全版的 Anaconda.
可以在清华的源去下载.
安装只需要下一步, 下一步即可. 给本地用户安装会安装到家目录下:
Miniconda 默认只会安装一个 Python 环境, 以及 Conda. 其他都需要自行安装.
所以 Miniconda 的版本号中带有 Python 的版本号.
2. 基本设置
安装完成后会在应用中默认配置两个命令行工具, 来自动加载环境变量.
默认是无法执行
conda
的.
为了方便, 可以加载环境变量后, 执行 conda init
, 该命令会在 powershell
中追加添加环境变量的指令.
家目录下, Documents 目录下 Powershell 目录下
如此每次打开终端都会默认激活 base
环境. 执行下面命令, 默认不激活任何环境.
激活对应环境, 所做任何操作(安装包等操作), 只对当前环境有关.
conda config --set auto_activate_base false
要手动激活环境, 可以执行 conda activate 环境名
.
想要取消该设置 (即自动激活), 可执行: conda config --set auto_activate_base true
实际上该操作会写入家目录下的配置文件中.
3. 配置源
需要配置的源有两个, 一个是 conda 的源, 一个是 pip 的源.
参考知乎的一篇文章.
3.1 配置 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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/
conda config --set show_channel_urls yes
北外源
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/
#Conda Forge
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/conda-forge/
#msys2(可略)
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/msys2/
#bioconda(可略)
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/bioconda/
#menpo(可略)
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/menpo/
#pytorch
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch/
# for legacy win-64(可略)
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/peterjc123/
conda config --set show_channel_urls yes
3.2 配置 pip
# 清华
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣
pip config set global.index-url http://pypi.douban.com/simple/
# 网易
pip config set global.index-url https://mirrors.163.com/pypi/simple/
临时用只需要使用 -i 源地址
作为命令行参数即可. 例如:
pip install xxx -i https://mirrors.163.com/pypi/simple/
可按照阿里的配置
创建/找到文件
~/.pip/pip.conf
添加下面代码
[global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com