在Ubuntu上安装和使用PyTorch的教程有很多,以下是一些常用的教程和资源:
sudo apt update
sudo apt install python3-venv
mkdir pytorch_env
cd pytorch_env
python3 -m venv pytorch_env
source pytorch_env/bin/activate
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
import torch
print(torch.__version__)
pip3 install torch torchvision torchaudio
sudo apt update
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc
conda create -n pytorch python3.8
conda activate pytorch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
conda install pytorch torchvision torchaudio pytorch-cuda11.7 -c pytorch -c nvidia
import torch
print(torch.__version__)
sudo apt install nvidia-cuda-toolkit nvidia-driver-510
wget https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda_11.1.1_455.32.00_linux.run
sudo sh cuda_11.1.1_455.32.00_linux.run
sudo cp cuda/include/cudnn.h /usr/local/cuda-11.1/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.1/lib64
sudo chmod a+r /usr/local/cuda-11.1/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.1/lib64/libcudnn*
pip3 install torch torchvision torchaudio -f https://download.pytorch.org/whl/torch_stable.html
希望这些教程能帮助你成功在Ubuntu上安装和使用PyTorch!