在Ubuntu上集成PyTorch可以通过多种方式实现,包括使用pip或Anaconda进行安装,并选择是否支持GPU加速。以下是详细的步骤:
sudo apt update
sudo apt install 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
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
python -c "import torch; print(torch.__version__)"
python -c "import torch; print(torch.cuda.is_available())"
以上步骤可以帮助您在Ubuntu系统上成功集成PyTorch,无论是用于CPU还是GPU加速的深度学习任务。请根据您的具体需求和系统配置选择合适的安装方法。