最新Conda使用清华源安装pytorch—GPU

1.配置.condarc文件

不同系统下的 .condarc 目录如下:
- Linux: ${HOME}/.condarc
- macOS: ${HOME}/.condarc
- Windows: C:\Users\<YourUserName>\.condarc

Windows 用户无法直接创建名为 .condarc 的文件,可先执行 

conda config --set show_channel_urls yes 

生成该文件之后再修改。然后就是配置.condarc文件:

channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch-lts/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/simpleitk/
show_channel_urls: true
default_channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

在之前的文件基础上对channels进行了增加。接下来简单介绍一下channels、default_channels、custom_channels:

  • channels 列表指定了 Conda 会优先从 上到下下载包。
  • default_channels 定义了 Conda 默认使用的官方源。
  • custom_channels 为某些特定的频道指定了自定义的 URL

故此,我在channels中加入了pytorch的URL。配置结束,使用下面命令清楚缓存后下载pytorch

conda clean -i

2.安装pytorch

安装环境:RTX3050,cuda11.7,python3.9.6

安装命令:

conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1

安装过程:

亲测时间:2024.09.20,但愿后续源还能用,不能用的话下载真的是太慢了,呜呜呜~

### 配置 Conda 使用清华大学镜像安装 PyTorch 为了确保顺利安装 GPU 版本的 PyTorch 并避免潜在问题,建议按照以下方法操作: #### 设置清华源作为默认通道 首先设置清华源为默认的 Anaconda 通道,这可以通过修改 `channels` 来实现。运行如下命令来添加多个必要的清华镜像源频道[^4]。 ```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/free conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 ``` #### 安装特定版本的 PyTorch 和依赖项 对于 CUDA 11.3 的环境,可以使用下面这条命令来指定安装带有相应 CUDA 工具包支持的 PyTorch、torchvision 和 torchaudio 版本[^1]。 ```bash conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ ``` 如果希望安装其他 CUDA 或者 PyTorch 版本,则可以根据需求调整上述命令中的版本号和 CUDA 套件版本。 #### 处理可能存在的冲突 有时可能会遇到名为 `cpuonly` 的软件包干扰 GPU 版本 PyTorch 的正常安装过程。为了避免这种情况发生,在尝试安装之前应该先确认当前环境中是否存在该软件包,并在必要时将其移除。 查看已安装的包列表并寻找 `cpuonly` 是否存在: ```bash conda list | grep cpuonly ``` 若有发现则通过下述指令予以删除: ```bash conda uninstall cpuonly ``` 完成以上步骤之后再次执行 PyTorch安装命令即可成功获取到所需的 GPU 加速版库文件。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值