pip和conda 添加国内清华镜像 让他下的更快

本文介绍如何配置Python的pip和conda源,以提高模块安装速度。包括阿里云和清华大学提供的镜像源配置方法,适用于Linux和Windows系统。
部署运行你感兴趣的模型镜像

---2019.12.2号更新,发现阿里云源好用---

永久使用:
Linux下:
修改 ~/.pip/pip.conf (没有.pip目录就在home目录创建一个.pip目录,在创建一个pip.conf文件), 往文件里写入下面两行,内容如下:

[global]
trusted-host=mirrors.aliyun.com
index-url=https://mirrors.aliyun.com/pypi/simple/

感觉阿里云的源比清华源好用,而且注意第二行一定要加,下面的清华源添加也是一样的,上面亲测很好用,直接照做

---------------------更新结束--------------

python模块安装,使用国内源可以提高下载速度。

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]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn

两种应该都可以,global可能是全局,也就是第一种直接在全局下,

  • 2

windows下:
直接在user目录中创建一个pip目录,如:C:\Users\xxxx\pip,新建文件pip.ini,内容如下,注意加trusted-host

要不然老是出错

 [global]
 index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  • 1
  • 2

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
  •  
  • 2

就可以了。
中科大的常用源:

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/

或者直接在.condarc文件写
 

总结:

pip 用阿里或清华源

conda 用清华或中科大

 

 

 

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

当然可以。`conda` `pip` 都是中国开发者常用的 Python 包管理工具,为了加快下载速度、提高安装效率,通常会设置国内镜像源。 ### pip 设置国内镜像 对于 `pip`, 我们可以通过指定命令行选项或修改配置文件的方式来使用国内镜像: #### 使用临时方法,在每次安装包的时候加上 `-i 参数` ```bash pip install <package_name> -i https://pypi.tuna.tsinghua.edu.cn/simple ``` #### 修改全局配置文件 (推荐) 你可以通过编辑 ~/.pip/pip.conf 文件(Windows 系统下是 %HOMEPATH%\pip\pip.ini) 来永久更改默认索引 URL: ```ini [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple ``` 也可以直接运行以下指令来创建该配置文件并添加内容: ```bash python -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple ``` ### Conda 设置国内镜像 对于 `Conda`, 它也支持类似的方式来进行加速下载: #### 添加清华等国内镜像到当前环境的 channels 列表里 ```bash conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ conda config --set show_channel_urls yes # 将默认 channel 更改为 tsinghua 源 conda config --prepend channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main ``` #### 直接在命令行中使用特定 mirror 地址 例如从 Tsinghua 的 Anaconda 镜像安装 numpy: ```bash conda install --channel=https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/mc/numpy ``` 以上就是关于如何为 `conda` `pip` 工具配置中国区镜像的方法了。如果你还有其他疑问或者其他想要了解的内容,请告诉我!
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值