在Ubuntu上配置PyTorch环境,你可以按照以下步骤进行:
安装Anaconda:
创建新的conda环境:
conda create -n pytorch_env python=3.8 # 选择你需要的Python版本
激活环境:
conda activate pytorch_env
安装PyTorch:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
验证安装:
python -c "import torch; print(torch.__version__)"
更新pip:
pip install --upgrade pip
安装PyTorch:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
pip install torch torchvision torchaudio
验证安装:
python -c "import torch; print(torch.__version__)"
如果你更喜欢使用Docker来管理环境,可以按照以下步骤进行:
安装Docker:
sudo apt update
sudo apt install docker.io
拉取PyTorch官方Docker镜像:
docker pull pytorch/pytorch:latest
运行Docker容器:
docker run -it --gpus all pytorch/pytorch:latest
在容器内验证安装:
python -c "import torch; print(torch.__version__)"
通过以上步骤,你应该能够在Ubuntu上成功配置PyTorch环境。