使用conda查看已安装的环境

    1. conda info --env

    如果没有Python3.8需要创建一个

    1. conda create --name d2l python=3.8 -y

    下载 D2L Notebook

    1. mkdir d2l-zh && cd d2l-zh
    2. curl https://zh-v2.d2l.ai/d2l-zh.zip -o d2l-zh.zip
    3. unzip d2l-zh.zip && rm d2l-zh.zip

    激活 d2l 环境

    1. conda activate d2l
    2. conda deactivate # 从环境中退出

    在安装深度学习框架之前,先检查计算机上是否有可用的 GPU

    1. lspci | grep -i vga
    2. 0b:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 30)

    无GPU先安装CPU版本的pytorch

    1. conda install pytorch torchvision torchaudio cpuonly -c pytorch
    2. # 查看pytorch版本
    3. import torch
    4. print(torch.__version__) #注意是双下划线
    5. # 本次安装为1.9.0

    还需要安装 d2l 软件包,它封装了本书中常用的函数和类。

    1. # -U:将所有包升级到最新的可用版本
    2. pip install -U d2l

    安装完成后,我们通过运行以下命令打开 Jupyter 笔记本:

    1. jupyter notebook

    参考:https://zh-v2.d2l.ai/chapter_installation/index.html