按官网文档下载安装1。
以下是安装命令
# Linux / Windows WSL
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
# Intel Mac
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh Miniconda3-latest-MacOSX-x86_64.sh
# M1 Mac
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
sh Miniconda3-latest-MacOSX-arm64.sh
打开命令行终端
Anaconda Powershell Prompt
,并输入以下代码:
python
版本(将会安装最新版),即注释的代码行
# conda create --name ai
conda create --name ai python=3.8
conda activate ai
# GPU, Windows/Linux
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
# CPU, Windows/Linux
conda install pytorch torchvision torchaudio cpuonly -c pytorch
# CPU, Mac
conda install pytorch torchvision torchaudio -c pytorch
python -c 'import torch; print(f"CUDA available? {torch.cuda.is_available()}"); print(torch.rand(5, 3));'
《动手学深度学习》中的辅助函数包:
pip install d2l
如果不使用IDE,建议安装Jupyter Lab
Jupyter
中打开# install jupyterlab
conda install -c conda-forge jupyterlab -y
验证安装是否成功:首先打开 Jupyter
:
cd code-data-folder
# cd /mnt/d/teach
jupyter lab
程序会自动跳转到默认浏览器,并访问网址http://localhost:8088。
下面测试pytorch
是否可用(in
JupyterLab
):
import torch
print(torch.rand(5, 3))
Amazon SageMaker Studio Lab2是《动手学深度学习》推荐的云服务平台。
需要能够访问Google服务,详见《深度学习21F》文档。
Usually a false alarm: restart the terminal. If the error persists:
try lower python versions
conda create --name ai python=3.6
, or write to the official
maintainers.
See: Quickstart @ pytorch.org3.