在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環境。