PyTorch 是一个广泛使用的深度学习框架,安装方式多样。以下是常见安装方法及步骤:

1. 从官网下载安装包

  • 访问 PyTorch官网 选择适合的版本
  • 下载对应系统的安装脚本(Linux/macOS/Windows)
  • 使用命令行执行安装:
    curl -L https://pytorch.org/whl/torch_stable.html | python -m pip install torch
    
PyTorch_官网

2. 使用 Conda 安装

  • 打开终端并运行:
    conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch
    
  • 确保已配置 Conda 环境
Conda_安装

3. 使用 Pip 安装

  • 执行以下命令(需提前安装 Python 和 CUDA):
    pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
    
Pip_安装

4. 验证安装

  • 在 Python 中运行:
    import torch
    print(torch.__version__)
    
  • 成功输出版本号即表示安装完成
终端_验证

如需进一步学习 PyTorch 使用,可访问 PyTorch入门教程