在Ubuntu系统上集成PyTorch可以通过多种方式实现,主要包括使用pip或Anaconda进行安装,并选择是否支持GPU加速。以下是详细的步骤:
sudo apt update
sudo apt upgrade
sudo apt install -y python3 python3-pip
python3 -m venv pytorch_env
source pytorch_env/bin/activate
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
请将118
替换为你的CUDA版本。
python -c "import torch; print(torch.__version__)"
wget https://repo.anaconda.com/archive/Anaconda3-2023.07-2-Linux-x86_64.sh
bash Anaconda3-2023.07-2-Linux-x86_64.sh
source ~/.bashrc
conda create -n pytorch_env python=3.8
conda activate pytorch_env
conda install pytorch torchvision torchaudio cpuonly -c pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch
请将11.7
替换为你的CUDA版本。
python -c "import torch; print(torch.cuda.is_available())"
通过以上步骤,你应该能够在Ubuntu系统上成功集成PyTorch,无论是用于CPU还是GPU加速的深度学习任务。