在Ubuntu上安裝PyTorch的步驟如下:
python3 --version
sudo apt update
sudo apt install python3
sudo apt install python3-pip
pip3 install --upgrade pip
nvcc --version
pip3 install torch torchvision torchaudio torchvision torchaudio cudatoolkit=<cuda_version> -c pytorch -c nvidia
其中<cuda_version>
應替換為你安裝的CUDA版本號。python3
import torch
print(torch.__version__)
if torch.cuda.is_available():
print("CUDA is available. You can use GPU.")
else:
print("CUDA is not available. Using CPU.")
以上步驟應該可以幫助你在Ubuntu上成功安裝PyTorch。如果在安裝過程中遇到問題,可以參考PyTorch官方文檔或社區論壇尋求幫助。