Anaconda安装源配置,pytorch,torchvision,torchaudio版本配置

本文介绍如何配置Anaconda的软件源以提高安装效率,并提供了针对不同需求的国内镜像源选择。此外,还详细说明了PyTorch及其相关包的安装流程与注意事项。

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

Anaconda安装源配置

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

Anaconda换源:
清华anaconda镜像:

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

pytorch(注意从清华源安装的默认为CPU版本)

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# 安装时PyTorch,官网给的安装命令需要去掉最后的-c pytorch,才能使用清华源
# conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
# msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
# bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
# menpo
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

中科大anaconda镜像

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

换回默认源

conda config --remove-key channels

Anaconda更新

# conda
conda update conda
# anaconda(升级anaconda前需要先升级conda)
conda update anaconda
# anaconda-navigator
conda update anaconda-navigator
# spyder
conda update spyder
# 所有包
conda update --all
# 尽量避免使用conda update --all命令,可能会出现部分包降级的问题

windows下Python更换国内pip源

1.在Windows下
(1)进入目录 C:\Users\计算机用户名
(2)新建一个文件夹pip

进入pip文件夹,新建一个TXT文本文件,命名为 pip.ini

编辑“pip.ini”文件,添加以下内容:在这里插入图片描述

阿里源

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

中科大源

[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host = pypi.mirrors.ustc.edu.cn

清华大学源

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

豆瓣源

[global]
index-url = http://pypi.douban.com/simple/[install]
trusted-host = mirrors.douban.com

修改后保存

测试
pip install pyinstaller

可能会出现的错误

ERROR: Could not find a version that satisfies the requirement pyinstall (from versions: none)
ERROR: No matching distribution found for pyinstall

  • 原因:没有装单独的Python(不是Anaconda里面的Python)
  • 解决1:装Python
  • 解决2:从GitHub找一个版本的pyinstal下载[https://github.com/pyinstaller/pyinstaller]),放到对应的文件夹里(Lib>site-packages>PyInstaller)

不同版本Pytorch安装

windows命令行切换管理员身份

命令行输入:

  • 查看当前账户是否为管理员账户:net localgroup administrators
  • 切换到管理员账户:runas /user:administrator cmd

torch,torchvision,torchaudio关系及安装顺序

  1. 需要先安装torch,再安装后两个包。因为torchvision和torchaudio都依赖torch包。
  2. 应该安装兼容的版本。例如torch 1.7, torchvision 0.8.1, torchaudio 0.7.2。版本需要对应。
  3. torch, torchvision和torchaudio都是PyTorch生态系统中的重要组件包。区别:
    • torch:PyTorch的核心包,提供张量和自动求导运算等基础功能。
    • torchvision:提供常用的图像和视频数据集,以及图像 transforms 的工具。依赖torch包。
    • torchaudio:提供音频数据加载功能和常用音频转换工具。依赖torch包。

下载地址:

torch,torchvision,torchaudio兼容版本及下载地址(https://download.pytorch.org/whl/torch_stable.html)

torch与torchvision的版本对照(更多参考https://gitcode.net/mirrors/pytorch/vision?utm_source=csdn_github_accelerator)

在这里插入图片描述

torch与torchaudio的版本对照(更多参考https://pytorch.org/audio/main/installation.html#compatibility-matrix)

在这里插入图片描述

<think>好的,用户想通过Conda安装CPU-only版本PyTorchTorchVisionTorchAudio。首先,我需要回忆一下相关的安装步骤和常见问题。根据之前的引用内容,用户可能遇到不同的安装命令,比如引用[1]和[3]提到正确的conda命令是`conda install pytorch torchvision torchaudio cpuonly -c pytorch`,而引用[2]指出老版本命令可能导致包缺失。这说明用户需要注意使用最新的安装命令以避免依赖问题。 接下来,我需要检查用户的需求是否明确。用户明确要求CPU-only版本,并且使用Conda安装,所以需要确保命令正确,并且不需要GPU相关的依赖。同时,用户可能已经安装Anaconda,如引用[4]所述,需要先启动Anaconda Prompt。 然后,思考安装步骤。首先创建虚拟环境是个好习惯,这样可以隔离不同项目的依赖。然后执行正确的conda命令。安装完成后,用户需要验证安装是否成功,比如导入PyTorch并检查版本和是否使用GPU。此外,用户可能关心版本兼容性问题,所以建议指定版本号,尤其是在需要特定版本的情况下。 还要考虑用户可能的误区,比如是否添加了正确的渠道(-c pytorch),否则可能导致下载源错误。另外,如果用户之前尝试过其他命令导致安装失败,可能需要先清理环境再重新安装。 最后,生成相关问题时要覆盖常见疑问,比如安装失败处理、GPU检查、版本指定和虚拟环境的重要性。这样用户能全面了解可能遇到的问题和解决方法。</think>### 分步解答 通过Conda安装PyTorch CPU-only版本的步骤如下: 1. **创建并激活虚拟环境(推荐)** ```bash conda create -n pytorch_cpu python=3.9 conda activate pytorch_cpu ``` 使用虚拟环境可避免依赖冲突[^4]。 2. **执行安装命令** ```bash conda install pytorch torchvision torchaudio cpuonly -c pytorch ``` 这是官方推荐的安装方式,确保同时安装`torchvision`和`torchaudio`[^1][^3]。 3. **验证安装** ```python import torch print(torch.__version__) # 应输出版本号,如2.0.1 print(torch.cuda.is_available()) # 应为False(CPU-only模式) ``` 4. **若安装失败的处理** - 检查是否添加了`-c pytorch`参数以指定官方源[^1]。 - 尝试清理缓存后重试: ```bash conda clean --all conda update --all ``` ### 注意事项 - 避免使用旧版本命令如`conda install pytorch torchvision cpuonly`,可能导致`torchaudio`缺失[^2]。 - 若需特定版本,可在命令中添加版本号,例如: ```bash conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cpuonly -c pytorch ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值