学习pytorch

环境

  1. conda 虚拟环境,我是创建conda create -n lmsl python=3.8 激活 conda activate lmls
    lmls 的意思是李沐老师

  2. 测试自己是不是安装好了需要的包
    import torch import torchvision
    import d2l print(“PyTorch version:”, torch.version)
    print("torchvision version:", torchvision.__version__) print(“d2l version:”, d2l.version)
    print("CUDA available:", torch.cuda.is_available())
    3.如果说你的下载速度太慢可以更换镜像
    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/cloud/conda-forge/ conda config --set show_channel_urls yes
    然后重新安装conda install d2l
    4.下载# 如果你需要支持 CUDA 12.3 conda install pytorch torchvision torchaudio cudatoolkit=12.3 -c pytorch
    我的不行还没有这个版本,我就下载了个·conda install pytorch torchvision torchaudio cudatoolkit=11.8 -c pytorch

    报错处理

    1. 报错 (lmsl) PS F:\class\sjwj_class> conda install pytorch torchvision torchaudio cudatoolkit=12.3 -c pytorch >> Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. Collecting package metadata (repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. PackagesNotFoundError: The following packages are not available from current channels: - cudatoolkit=12.3 Current channels: - https://conda.anaconda.org/pytorch/win-64 - https://conda.anaconda.org/pytorch/noarch - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/noarch - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch - https://repo.anaconda.com/pkgs/main/win-64 - https://repo.anaconda.com/pkgs/main/noarch - https://repo.anaconda.com/pkgs/r/win-64 - https://repo.anaconda.com/pkgs/r/noarch - https://repo.anaconda.com/pkgs/msys2/win-64 - https://repo.anaconda.com/pkgs/msys2/noarch To search for alternate channels that may provide the conda package you’re looking for, navigate to https://anaconda.org and use the search bar at the top of the page.
      解决:
      这个错误表明当前的 Conda 渠道中找不到指定版本的 cudatoolkit=12.3。解决这个问题的方法有几个,你可以尝试以下步骤:
  3. 检查可用的 CUDA Toolkit 版本
    首先,确定当前可用的 CUDA Toolkit 版本。你可以通过以下命令查看 PyTorch 可用的 CUDA 版本:

conda search cudatoolkit

这将列出所有可用的 CUDA Toolkit 版本,你可以选择一个可用的版本进行安装。2. 安装其他版本的 CUDA Toolkit
12.3 不可用,可以尝试安装其他版本。例如,假设 11.8 是可用的版本,你可以运行:

conda install pytorch torchvision torchaudio cudatoolkit=11.8 -c pytorch
  1. 更新 Conda
    有时候更新 Conda 可以解决一些包的冲突或找不到的问题。你可以运行以下命令来更新 Conda:
conda update conda

4. 使用 pip 安装

如果你无法通过 Conda 安装,你还可以考虑使用 pip 安装 PyTorch 和相关库。以下是使用 pip 安装的命令(假设你不需要 CUDA 支持):

pip install torch torchvision torchaudio

如果需要 CUDA 支持,可以在 PyTorch 的官方网站找到对应的安装命令,通常是如下形式(替换 CUDA 版本):

pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 -f https://download.pytorch.org/whl/torch_stable.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值