以下是在Linux系统中安装PyTorch的步骤:
sudo apt update和sudo apt install python3 python3-pip;对于RPM系(如CentOS),运行sudo yum install python3 python3-pip。python3 -m venv pytorch_env,然后source pytorch_env/bin/activate。pip3 install torch torchvision torchaudio;若用GPU版本,需先安装对应版本的CUDA Toolkit和cuDNN,然后运行pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu版本号,如pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118。bash Miniconda3-latest-Linux-x86_64.sh,并按提示操作。conda create -n pytorch_env python=3.8,conda activate pytorch_env。conda install pytorch torchvision torchaudio cpuonly -c pytorch;GPU版本用conda install pytorch torchvision torchaudio cudatoolkit=版本号 -c pytorch -c nvidia,版本号要和CUDA一致。import torch; print(torch.__version__),若显示版本号则安装成功。