pip和conda 添加国内清华镜像
直接在user目录中创建一个pip目录,如:C:\Users\xxxx\pip,新建文件pip.ini,内容如下,注意加trusted-host要不然老是出错。意思如果用conda安装包,会优先用https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/这个清华源。比如清华的源我之前只加了https://mirrors.tuna.tsinghu
镜像站提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch 等,各镜像站镜像的第三方源并不相同,可以参考下方「第三方镜像源」一节)的镜像,各系统都可以通过修改用户目录下的 .condarc 文件来使用镜像站。
不同系统下的 .condarc 目录如下:
- Linux: ${HOME}/.condarc
- macOS: ${HOME}/.condarc
- Windows: C:\Users\<YourUserName>\.condarc
注:
* Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。
* 由于更新过快难以同步,TUNA 等镜像站不同步 pytorch-nightly , pytorch-nightly-cpu , ignite-nightly 这三个包。
* 如果您正在从某一镜像源切换到另一镜像源,请检查镜像源是否同步了您所需要的 repo,以及该 repo 是否支持您使用的平台 (e.g. linux-64)。
* 为了保证以下配置在所有镜像站可用,配置中只加入了少量必须的第三方源,您可以在下方的列表中自行寻找并添加其他第三方源。
---------------------------------------------------------------------------------------------------------------------
pip源更改:
pip源有好几个,我一直用的清华的pip源,它5分钟同步一次。
临时使用:
pip 后加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple
例1:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
例2:我想安装tensorflow-gpu1.4.1,执行:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.4.1
我们可以点进去那个清华链接,这个链接和下面那个conda的清华链接不太一样,注意,有非常多的镜像
永久使用:
Linux下:
修改 ~/.pip/pip.conf (没有.pip目录就在home目录创建一个.pip目录,在创建一个pip.conf文件), 往文件里写入下面两行,内容如下:
[global]
trusted-host=pypi.tuna.tsinghua.edu.cn
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[global]
trusted-host=mirrors.aliyun.com
index-url=https://mirrors.aliyun.com/pypi/simple/
不过有的博客我看到这样写,多了一行:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
windows下:
直接在user目录中创建一个pip目录,如:C:\Users\xxxx\pip,新建文件pip.ini,内容如下,注意加trusted-host要不然老是出错
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
---------------------------------------------------------------------------------------------------------------------------------
conda源更改:
conda源国内有清华,中科大,阿里云,注意,同一个源可以加不同的链接,
比如清华的源我之前只加了https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
但是有些包在别的地方,比如pytorch包在
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
注意如果需要pytorch, 还需要添加pytorch的镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
注意:
;'PyTorch 官网给的安装命令需要去掉最后的 -c pytorch ,这样才能享受清华源的高速。
所以可以都加进去
-----------
修改源只需输入如下两行命令:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
输完后,会在home目录生成一个.condarc文件,后面可以通过编辑这个文件来改变源,比如现在.condarc文件内容如下:
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
意思如果用conda安装包,会优先用https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/这个清华源
如果没有,会依次往下顺延至defaults也就是用默认源,有的说把defaults会快点
现在我在想添加一个中科大的源和清华其他的源,直接将链接写入文件,如下:
阿里云好像只有pip的源,conda的没找到,也可以自己点链接进去,看看网址里面都有什么包
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
就可以了。
中科大的常用源:
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
使用下列命令清除索引缓存,并安装常用包测试一下。
conda clean -i conda create -n myenv numpy
conda config --set custom_channels.auto https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
或者直接在.condarc文件写
总结:
pip 用阿里或清华源
conda 用清华或中科大
所有评论(0)