安装pytorch 对应李沐d2l 环境安装

  • 过程问题
    • 1 安装问题
    • 2 从头检查环境
    • 3 CUDA
    • 4 测试pytorch
    • 5 安装 d2l 软件包
    • 6 开始使用d2l
    • 7 遗留问题
    • 8 已安装的软件包
    • 9 问题AttributeError: module 'torch' has no attribute 'plot'

过程问题

1 安装问题

anaconda prompt (anaconda3)base 环境下

WARNING: You are using pip version 21.1.1; however, version 22.0.4 is available.

升级pip

python -m pip install --upgrade pip

未成功

2 从头检查环境

cmd下

python
Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activationC:\Users\>conda activate(base) C:\Users\>conda --version
conda 4.9.2

conda安装,输入 conda --version
输入 conda info ,出现info内容则校验成功

conda config --show channels
channels:- defaults- (base) C:\Users\>conda config --show channels
channels:- defaults
(base) C:\Users\>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/(base) C:\Users\>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/(base) C:\Users\>conda config --set show_channel_urls yes(base) C:\Users\>conda config --show channels
channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/- defaults

该步未尝试
~~修改此文件,采用清华源
/.condarc:~

channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free- defaults
default_channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge- https://repo.continuum.io/pkgs/free- https://repo.continuum.io/pkgs/r- https://repo.continuum.io/pkgs/pro

3 CUDA

CUDA安装成功

C:\Users\>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Tue_Sep_15_19:12:04_Pacific_Daylight_Time_2020
Cuda compilation tools, release 11.1, V11.1.74
Build cuda_11.1.relgpu_drvr455TC455_06.29069683_0

4 测试pytorch

测试pytorch

import torch
x = torch.rand(2,3)
print(x)

应该输出的内容

tensor([[0.8159, 0.1670, 0.9336],[0.9877, 0.6789, 0.2509]])
torch.cuda.is_available()
True

此时,GPU驱动和CUDA可支持pytorch的加速计算。
打开anaconda navigator,点击左边enviroment,然后creat d2l

5 安装 d2l 软件包

进入d2l-zh\pytorch 的cmd里
安装成功以后还需要安装 d2l 软件包,它封装了本书中常用的函数和类。

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

D:\d2l\d2l-zh\pytorch>pip install -U d2l

6 开始使用d2l

打开anaconda prompt

conda activate d2l

退出输入

conda deactivate

7 遗留问题

paddlepaddle 2.1.0 环境与李沐d2l 环境产生冲突

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
paddlepaddle 2.1.0 requires numpy<=1.19.3,>=1.13; python_version >= "3.5" and platform_system == "Windows", but you have numpy 1.22.2 which is incompatible.
mxnet 1.7.0.post2 requires numpy<1.17.0,>=1.8.2, but you have numpy 1.22.2 which is incompatible.
mxnet 1.7.0.post2 requires requests<2.19.0,>=2.18.4, but you have requests 2.25.1 which is incompatible.
WARNING: You are using pip version 21.1.1; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\Anaconda3\python.exe -m pip install --upgrade pip' command.
Successfully installed d2l-0.17.4 matplotlib-3.4.0 numpy-1.22.2 pandas-1.2.4

pip 的依赖项解析器当前未考虑安装的所有包。此行为是以下依赖项冲突的根源。
paddlepaddle 2.1.0
mxnet 1.7.0
要求包低
incompatible 不匹配
于是:
就重新安装这几个包
pip install 包名 -i 地址

pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple  # 清华

8 已安装的软件包

查看已安装的软件包
pip list

pip list
Package                            Version
---------------------------------- -------------------
alabaster                          0.7.12
anaconda-client                    1.7.2
anaconda-navigator                 1.10.0
anaconda-project                   0.8.3
argh                               0.26.2
argon2-cffi                        20.1.0
asn1crypto                         1.4.0
astor                              0.8.1
astroid                            2.4.2
astropy                            4.0.2
async-generator                    1.10
atomicwrites                       1.4.0
attrs                              20.3.0
autopep8                           1.5.4
Babel                              2.8.1
backcall                           0.2.0
backports.functools-lru-cache      1.6.1
backports.shutil-get-terminal-size 1.0.0
backports.tempfile                 1.0
backports.weakref                  1.0.post1
bcrypt                             3.2.0
beautifulsoup4                     4.9.3
bitarray                           1.6.1
bkcharts                           0.2
bleach                             3.2.1
bokeh                              2.2.3
boto                               2.49.0
Bottleneck                         1.3.2
brotlipy                           0.7.0
certifi                            2020.6.20
cffi                               1.14.3
chardet                            3.0.4
click                              7.1.2
cloudpickle                        1.6.0
clyent                             1.2.2
colorama                           0.4.4
comtypes                           1.1.7
conda                              4.9.2
conda-build                        3.20.5
conda-package-handling             1.7.2
conda-verify                       3.4.2
contextlib2                        0.6.0.post1
cryptography                       3.1.1
cycler                             0.10.0
Cython                             0.29.21
cytoolz                            0.11.0
d2l                                0.17.4
dask                               2.30.0
decorator                          4.4.2
defusedxml                         0.6.0
diff-match-patch                   20200713
distributed                        2.30.1
docutils                           0.16
entrypoints                        0.3
et-xmlfile                         1.0.1
fastcache                          1.1.0
filelock                           3.0.12
flake8                             3.8.4
Flask                              1.1.2
fsspec                             0.8.3
future                             0.18.2
gast                               0.3.3
gevent                             20.9.0
glob2                              0.7
graphviz                           0.8.4
greenlet                           0.4.17
h5py                               2.10.0
HeapDict                           1.0.1
html5lib                           1.1
idna                               2.6
imageio                            2.9.0
imagesize                          1.2.0
importlib-metadata                 2.0.0
iniconfig                          1.1.1
intervaltree                       3.1.0
ipykernel                          5.3.4
ipython                            7.19.0
ipython-genutils                   0.2.0
ipywidgets                         7.5.1
isort                              5.6.4
itsdangerous                       1.1.0
jdcal                              1.4.1
jedi                               0.17.1
jieba                              0.42.1
Jinja2                             2.11.2
joblib                             0.17.0
json5                              0.9.5
jsonschema                         3.2.0
jupyter                            1.0.0
jupyter-client                     6.1.7
jupyter-console                    6.2.0
jupyter-core                       4.6.3
jupyterlab                         2.2.6
jupyterlab-pygments                0.1.2
jupyterlab-server                  1.2.0
keyring                            21.4.0
kiwisolver                         1.3.0
lazy-object-proxy                  1.4.3
libarchive-c                       2.9
llvmlite                           0.34.0
locket                             0.2.0
lxml                               4.6.1
MarkupSafe                         1.1.1
matplotlib                         3.4.0
mccabe                             0.6.1
menuinst                           1.4.16
mistune                            0.8.4
mkl-fft                            1.2.0
mkl-random                         1.1.1
mkl-service                        2.3.0
mock                               4.0.2
more-itertools                     8.6.0
mpmath                             1.1.0
msgpack                            1.0.0
multipledispatch                   0.6.0
mxnet                              1.7.0.post2
navigator-updater                  0.2.1
nbclient                           0.5.1
nbconvert                          6.0.7
nbformat                           5.0.8
nest-asyncio                       1.4.2
networkx                           2.5
nltk                               3.5
nose                               1.3.7
notebook                           6.1.4
numba                              0.51.2
numexpr                            2.7.1
numpy                              1.22.2
numpydoc                           1.1.0
olefile                            0.46
openpyxl                           3.0.5
packaging                          20.4
paddlepaddle                       2.1.0
pandas                             1.2.4
pandocfilters                      1.4.3
paramiko                           2.7.2
parso                              0.7.0
partd                              1.1.0
path                               15.0.0
pathlib2                           2.3.5
pathtools                          0.1.2
patsy                              0.5.1
pep8                               1.7.1
pexpect                            4.8.0
pickleshare                        0.7.5
Pillow                             8.0.1
pip                                21.1.1
pkginfo                            1.6.1
pluggy                             0.13.1
ply                                3.11
prometheus-client                  0.8.0
prompt-toolkit                     3.0.8
protobuf                           3.17.2
psutil                             5.7.2
py                                 1.9.0
pycodestyle                        2.6.0
pycosat                            0.6.3
pycparser                          2.20
pycurl                             7.43.0.6
pydocstyle                         5.1.1
pyflakes                           2.2.0
Pygments                           2.7.2
pylint                             2.6.0
PyNaCl                             1.4.0
pyodbc                             4.0.0-unsupported
pyOpenSSL                          19.1.0
pyparsing                          2.4.7
pyreadline                         2.1
pyrsistent                         0.17.3
PySocks                            1.7.1
pytest                             0.0.0
python-dateutil                    2.8.1
python-jsonrpc-server              0.4.0
python-language-server             0.35.1
pytz                               2020.1
PyWavelets                         1.1.1
pywin32                            227
pywin32-ctypes                     0.2.0
pywinpty                           0.5.7
PyYAML                             5.3.1
pyzmq                              19.0.2
QDarkStyle                         2.8.1
QtAwesome                          1.0.1
qtconsole                          4.7.7
QtPy                               1.9.0
regex                              2020.10.15
requests                           2.25.1
rope                               0.18.0
Rtree                              0.9.4
ruamel-yaml                        0.15.87
scikit-image                       0.17.2
scikit-learn                       0.24.2
scipy                              1.5.2
seaborn                            0.11.0
Send2Trash                         1.5.0
setuptools                         50.3.1.post20201107
simplegeneric                      0.8.1
singledispatch                     3.4.0.3
sip                                4.19.13
six                                1.15.0
snowballstemmer                    2.0.0
sortedcollections                  1.2.1
sortedcontainers                   2.2.2
soupsieve                          2.0.1
Sphinx                             3.2.1
sphinxcontrib-applehelp            1.0.2
sphinxcontrib-devhelp              1.0.2
sphinxcontrib-htmlhelp             1.0.3
sphinxcontrib-jsmath               1.0.1
sphinxcontrib-qthelp               1.0.3
sphinxcontrib-serializinghtml      1.1.4
sphinxcontrib-websupport           1.2.4
spyder                             4.1.5
spyder-kernels                     1.9.4
SQLAlchemy                         1.3.20
statsmodels                        0.12.0
sympy                              1.6.2
tables                             3.6.1
tblib                              1.7.0
tensorboardX                       2.2
terminado                          0.9.1
testpath                           0.4.4
threadpoolctl                      2.1.0
tifffile                           2020.10.1
toml                               0.10.1
toolz                              0.11.1
torch                              1.8.1+cu111
torchaudio                         0.8.1
torchtext                          0.4.0
torchvision                        0.9.1+cu111
tornado                            6.0.4
tqdm                               4.50.2
traitlets                          5.0.5
typing-extensions                  3.7.4.3
ujson                              4.0.1
unicodecsv                         0.14.1
urllib3                            1.22
watchdog                           0.10.3
wcwidth                            0.2.5
webencodings                       0.5.1
Werkzeug                           1.0.1
wheel                              0.35.1
widgetsnbextension                 3.5.1
win-inet-pton                      1.1.0
win-unicode-console                0.5
wincertstore                       0.2
wrapt                              1.11.2
xlrd                               1.2.0
XlsxWriter                         1.3.7
xlwings                            0.20.8
xlwt                               1.3.0
xmltodict                          0.12.0
yapf                               0.30.0
zict                               2.0.0
zipp                               3.4.0
zope.event                         4.5.0
zope.interface                     5.1.2
WARNING: You are using pip version 21.1.1; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\Anaconda3\python.exe -m pip install --upgrade pip' command.

1链接: link.
pip 工具 _ Python 包管理工具常用命令及镜像地址

9 问题AttributeError: module ‘torch’ has no attribute ‘plot’

在linear-regression中

该步中
再次使用numpy进行可视化

x = np.arange(-7, 7, 0.01)均值和标准差对params = [(0, 1), (0, 2), (3, 1)]
d2l.plot(x, [normal(x, mu, sigma) for mu, sigma in params], xlabel='x',ylabel='p(x)', figsize=(4.5, 2.5),legend=[f'mean {mu}, std {sigma}' for mu, sigma in params])

产生如下错误

AttributeError           Traceback (most recent call last)
<ipython-input-13-f717769c2c17> in <module>4 # 均值和标准差对5 params = [(0, 1), (0, 2), (3, 1)]
----> 6 d2l.plot(x, [normal(x, mu, sigma) for mu, sigma in params], xlabel='x',7          ylabel='p(x)', figsize=(4.5, 2.5),8          legend=[f'mean {mu}, std {sigma}' for mu, sigma in params])AttributeError: module 'torch' has no attribute 'plot'

按上述步骤从头重新配置环境后解决问题。

注意jupyter notebook(anaconda3)中可以直接启动http://localhost:8888/
若需要jupyter打开的目录是D盘:
首先打开cmd输入命令 cd /d D:

cd /d D:
jupyter notebook

即可

李沐d2l 环境安装相关推荐

  1. 李沐d2l《动手学深度学习》第二版——风格迁移源码详解

    本文是对李沐Dive to DL<动手学深度学习>第二版13.12节风格迁移的源码详解,整体由Jupyter+VSCode完成,几乎所有重要代码均给出了注释,一看就懂.需要的同学可以在文末 ...

  2. 关于安装李沐深度学习d2l包报错的解决办法(保姆教程)

    目录:d2l包安装失败的解决过程 前言 一.李沐提供的安装方式 1. 创建一个新的环境 2. 激活 d2l 环境 3. 安装深度学习框架和d2l软件包 3.1 安装PyTorch的CPU或GPU版本 ...

  3. 李沐《动手学深度学习》d2l——安装和使用

    今天想要跟着沐神学习一下循环神经网络,在跑代码的时候,d2l出现了问题,这里记录一下解决的过程,方便以后查阅. 李沐<动手学深度学习>d2l--安装和使用 安装d2l 解决 Import ...

  4. 关于李沐动手学深度学习(d2l)pytorch环境本地配置

    本地安装d2l 由于之前试了很多次d2l课本的安装方法失败了,这里提供一种我可以成功安装d2l包的方法. pytorch安装 首先安装cuda.cudnn.pytroch(gpu版本).可以参考这篇文 ...

  5. 李沐《动手学深度学习》第二版 pytorch笔记1 环境搭建

    李沐<动手学深度学习>第二版pytorch笔记1 搭建环境 文章目录 李沐<动手学深度学习>第二版pytorch笔记1 搭建环境 此时尚有耐心 虚拟环境搭建 创建虚拟环境 查看 ...

  6. 李沐课程中:from d2l import torch as d2l报错

    问题描述: 我是用pycharm跑的李沐大神的代码,代码是从GitHub(https://github.com/Miraclelucy/dive-into-deep-learninghttps://g ...

  7. 李沐动手学深度学习(pytorch版本)d2lzh_pytorch包的缺少安装问题

    学习深度学习时候,很多人参考的是李沐的动手学深度学习Pytorch版本(附上官方地址:https://tangshusen.me/Dive-into-DL-PyTorch/#/). 在学习3.5.1节 ...

  8. 动手学深度学习V2——李沐Bilibili直播视频Jupyter Notebook安装

    在哔哩哔哩上发现李沐是视频直播讲解<动手学深度V2>- Pytorch,准备按照视频中的安装教程来搭建一个新的虚拟环境d2l,李沐使用的是Jupyter Notebook 而不是 Pych ...

  9. 推荐:李沐开源新作,一起来《动手学深度学习》

    来源 /Datawhale 图文 / 静修   排版 / 家豪 [导读]<动手学深度学习>这本书由亚马逊首席科学家李沐,亚马逊应用科学家阿斯顿·张等大师合作打造,沉淀三年完成.本书采用交互 ...

  10. windows上配置深度学习(李沐-动手学深度学习)

    1.安装miniconda windows下安装,去清华大学开源镜像下载,速度比较快. 选中Miniconda3-latest-Windos-x86_64.exe下载安装包(目前最新的是py3.9) ...

最新文章

  1. PyQt5 笔记(04):主窗口卡死问题
  2. 机器学习模型部署_9月版部署机器学习模型
  3. 如何学习数据结构和算法——大佬文章汇总
  4. ASP.NET的学习之asp.net整体运行机制
  5. UIPickerView的使用
  6. Java 原生 JAXB 解析 XML 深入剖析
  7. 计算机处理器显卡,怎么看处理器cpu和显卡
  8. javascript——构造函数和原型对象
  9. 计算机主板知识,电脑主板知识:主板板型、接口、做工与选购详解
  10. 【C++】c++修改IE浏览器的Internet选项
  11. java io closed_java.io.IOException: Stream closed 异常的原因和处理
  12. Android 根据逗号分隔String
  13. 我的世界服务器显示文字,我的世界服务器悬浮字体教程 | 手游网游页游攻略大全...
  14. cron表达式解析 + robfig/cron 源码剖析
  15. 16进制几个字符是一个字节
  16. Android 仿微信多语言切换
  17. 写字机上位机c语言,易懂 | 手把手教你编写你的第一个上位机
  18. 模拟开关CD4051使用的4个要点
  19. 10分钟科普:人工智能是什么?它又是如何工作的呢?(上)
  20. matlab中软开关,数字化软开关电源的Matlab仿真研究

热门文章

  1. matlab一阶导数图,一阶微分excel【如何用EXCEL做一阶导数图?】
  2. mysql基础命令(一)
  3. 怎么用阿里云服务器部署项目?上传简单项目
  4. OSPF协议总结5(六种LSA)
  5. iOS15新特性、iOS15适配
  6. springboot 多模块 Found multiple @SpringBootConfiguration annotated classes
  7. python游戏制作rpg_python实现的简单RPG游戏流程实例
  8. 谈读《三国志》 ——开篇引述 【istrangeboy原创】
  9. 【线上沙龙】WeTest携手Testerhome共探DevOps下的质量保障
  10. 「LCA」[USACO10HOL]牛的政治Cow Politics