conda和pip设置国内下载源

本文详细介绍如何通过修改Anaconda和pip的配置文件,使用清华大学的镜像源,以加快Python包的下载速度。具体步骤包括添加镜像源到conda的渠道列表,以及设置pip的index-url为清华镜像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

执行如下命令

  1. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

  2. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

  3. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

  4. conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/

  5. conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

  6. conda config --append channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/

  7. conda config --set show_channel_urls yes   # 搜索时显示通道地址

windows下,在用户目录中,打开.condarc,发现配置已经加上了

运行conda install pandas,看到下载源已经改变了

2、pip设置下载源

windows下,直接在用户目录中创建一个pip目录,新建pip.ini

添加

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

测试安装 pip install xlrd,下载源更改

当然可以。`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` 工具配置中国区镜像的方法了。如果你还有其他疑问或者其他想要了解的内容,请告诉我!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值