pip conda 源 清华

本文介绍如何配置conda和pip使用国内镜像源,包括清华大学、阿里云等提供的镜像服务,以加快软件包的下载速度。提供了Linux和Windows系统的详细配置步骤。

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

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 --set show_channel_urls yes

PIP

国内源:

新版ubuntu要求使用https源,要注意。

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

豆瓣:http://pypi.douban.com/simple/

临时使用:

可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple

例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库。

永久修改,一劳永逸:

Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)

内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com

windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini。内容同上。

### 配置清华并安装 PyTorch #### 使用 Pip 安装 PyTorch 为了通过清华大学的镜像加速 `pip` 的安装过程,可以按照以下方法操作: 1. **设置临时镜像** 如果仅希望在当前命令中使用清华大学的镜像来安装包,可以直接指定 `-i` 参数。例如,要安装某个 Python 包(假设为 `package`),可以通过如下方式实现[^1]: ```bash pip install -i https://pypi.tuna.tsinghua.edu.cn/simple package ``` 2. **升级 Pip 到最新版本** 在安装 PyTorch 前,建议先确保虚拟环境中使用的 `pip` 是最新的版本,这有助于避免潜在兼容性问题[^2]: ```bash python -m pip install --upgrade pip ``` 3. **正式安装 PyTorch** 接下来,可通过官方推荐的方式下载适合系统的 PyTorch 版本。通常情况下,PyTorch 提供了一个便捷工具页面用于生成对应的安装命令。访问 [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/) 并根据操作系统、Python 版本以及 CUDA 支持情况获取具体命令。 若需要手动替换为清华大学的 PyPI ,则可尝试类似的结构化命令: ```bash pip install torch torchvision torchaudio -f https://download.pytorch.org/whl/cu117/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple ``` --- #### 使用 Conda 安装 PyTorch 对于 Anaconda 用户来说,配置清华大学的镜像能够显著提升依赖项解决速度和整体性能。 1. **添加清华镜像作为默认通道** 若要长期利用该资库,需执行以下指令以修改 `.condarc` 文件的内容[^3]: ```bash conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/ conda config --set show_channel_urls yes ``` 2. **验证配置更改成功与否** 可运行下面这条语句查看已设定好的 channel 是否包含上述地址之一: ```bash conda config --show-sources ``` 3. **实际安装流程** 当完成以上准备工作之后,就可以轻松地调用标准形式去部署所需的深度学习框架及其关联组件了。比如这里我们打算引入支持特定版本 cuda 工具集 (此处设定了 9.0) 下面两个主要模块即 PyTorch 和 TorchVision : ```bash conda install pytorch torchvision cudatoolkit=9.0 -c pytorch ``` --- ### 总结 无论是采用 `pip` 还是 `conda` 方法,在适当调整好对应国内高效分发站点链接的基础上都可以顺利完成目标软件栈搭建工作。同时提醒注意各自平台特性差异可能带来的细微区别处理需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值