动手学深度学习-08线性回归+基础优化算法时的一些问题

1. %matplotlib inline在pycharm中报错

%matplotlib inline只能在ipython或jupyter notebook中用

%matplotlib inline作用是在console生成图像,而不用弹窗显示。
如果要在pycharm中使用,则要删除或注释掉%matplotlib inline,并另外调用matplotlib画图功能,在代码后加上:

plt.show()

示例:

d2l.set_figsize()
d2l.plt.scatter(features[:, 1].detach().numpy(), labels.detach().numpy(),1);
d2l.plt.show()

2. from d2l import torch as d2l

在Colab上的报错:

执行以下代码:

!pip install matplotlib_inline

若colab提示找不到d2l,可以按以下处理:

!pip install -U d2l

但我直接建议输入下面的命令:

!pip install d2l==0.14.

在一开始直接输入!pip install d2l==0.14.,基本不需要输入!pip install matplotlib_inline,!pip install matplotlib==3.0.0,!pip install -U d2l等所有命令了

(本地pycharm上d2l的安装)

我在pycharm终端装d2l时,下了一连串的库,不知道其他人是不是这样,当时我看见要下那么多东西,而且好长时间都下不完,心里可慌了。。。 (下面的还不是全部)

D:\pycharmprojection\deep_learn>pip install -U d2l
Collecting d2l
  Using cached d2l-0.17.6-py3-none-any.whl (112 kB)
Collecting matplotlib==3.5.1
  Using cached matplotlib-3.5.1-cp38-cp38-win_amd64.whl (7.2 MB)
Collecting jupyter==1.0.0
  Using cached jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB)
Collecting requests==2.25.1
  Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
     ---------------------------------------- 61.2/61.2 kB 1.6 MB/s eta 0:00:00
Collecting pandas==1.2.4
  Using cached pandas-1.2.4-cp38-cp38-win_amd64.whl (9.3 MB)
Collecting numpy==1.21.5
  Using cached numpy-1.21.5-cp38-cp38-win_amd64.whl (14.0 MB)
Collecting ipywidgets
  Using cached ipywidgets-8.0.5-py3-none-any.whl (138 kB)
Collecting notebook
  Using cached notebook-6.5.3-py3-none-any.whl (529 kB)
Collecting nbconvert
  Using cached nbconvert-7.2.10-py3-none-any.whl (275 kB)
Collecting jupyter-console
  Using cached jupyter_console-6.6.3-py3-none-any.whl (24 kB)
Collecting qtconsole
  Using cached qtconsole-5.4.1-py3-none-any.whl (120 kB)
Collecting ipykernel
  Using cached ipykernel-6.22.0-py3-none-any.whl (149 kB)
Requirement already satisfied: cycler>=0.10 in d:\program files\python\python38\lib\site-packages (from matplotlib==3.5.1->d2l) (0.10.0)
Requirement already satisfied: python-dateutil>=2.7 in d:\program files\python\python38\lib\site-packages (from matplotlib==3.5.1->d2l) (2.8.1)
Requirement already satisfied: pillow>=6.2.0 in d:\program files\python\python38\lib\site-packages (from matplotlib==3.5.1->d2l) (9.3.0)
Requirement already satisfied: kiwisolver>=1.0.1 in d:\program files\python\python38\lib\site-packages (from matplotlib==3.5.1->d2l) (1.3.2)
Collecting packaging>=20.0
  Using cached packaging-23.0-py3-none-any.whl (42 kB)
Collecting fonttools>=4.22.0
  Downloading fonttools-4.39.2-py3-none-any.whl (1.0 MB)
     ---------------------------------------- 1.0/1.0 MB 80.0 kB/s eta 0:00:00
Requirement already satisfied: pyparsing>=2.2.1 in d:\program files\python\python38\lib\site-packages (from matplotlib==3.5.1->d2l) (2.4.7)
Requirement already satisfied: pytz>=2017.3 in d:\program files\python\python38\lib\site-packages (from pandas==1.2.4->d2l) (2021.1)
Collecting chardet<5,>=3.0.2
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
     ---------------------------------------- 178.7/178.7 kB 118.5 kB/s eta 0:00:00
Requirement already satisfied: certifi>=2017.4.17 in d:\program files\python\python38\lib\site-packages (from requests==2.25.1->d2l) (2022.6.15)
Collecting idna<3,>=2.5
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
     ---------------------------------------- 58.8/58.8 kB 155.2 kB/s eta 0:00:00
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\program files\python\python38\lib\site-packages (from requests==2.25.1->d2l) (1.26.11)
Requirement already satisfied: six in d:\program files\python\python38\lib\site-packages (from cycler>=0.10->matplotlib==3.5.1->d2l) (1.15.0)
Collecting jupyter-core!=5.0.*,>=4.12
  Using cached jupyter_core-5.3.0-py3-none-any.whl (93 kB)
Collecting psutil
  Using cached psutil-5.9.4-cp36-abi3-win_amd64.whl (252 kB)
Collecting pyzmq>=20
  Using cached pyzmq-25.0.2-cp38-cp38-win_amd64.whl (1.1 MB)
Collecting tornado>=6.1
  Using cached tornado-6.2-cp37-abi3-win_amd64.whl (425 kB)
Collecting debugpy>=1.6.5
  Using cached debugpy-1.6.6-cp38-cp38-win_amd64.whl (4.9 MB)
Collecting jupyter-client>=6.1.12
  Using cached jupyter_client-8.1.0-py3-none-any.whl (102 kB)
Collecting matplotlib-inline>=0.1
  Using cached matplotlib_inline-0.1.6-py3-none-any.whl (9.4 kB)
Collecting ipython>=7.23.1
  Using cached ipython-8.11.0-py3-none-any.whl (793 kB)
Collecting nest-asyncio
  Using cached nest_asyncio-1.5.6-py3-none-any.whl (5.2 kB)
Collecting traitlets>=5.4.0
  Using cached traitlets-5.9.0-py3-none-any.whl (117 kB)
Collecting comm>=0.1.1
  Using cached comm-0.1.3-py3-none-any.whl (6.6 kB)
Collecting jupyterlab-widgets~=3.0
  Using cached jupyterlab_widgets-3.0.6-py3-none-any.whl (198 kB)
Collecting widgetsnbextension~=4.0
  Using cached widgetsnbextension-4.0.6-py3-none-any.whl (2.1 MB)
Collecting pygments
  Using cached Pygments-2.14.0-py3-none-any.whl (1.1 MB)
Collecting prompt-toolkit>=3.0.30
  Using cached prompt_toolkit-3.0.38-py3-none-any.whl (385 kB)
Collecting mistune<3,>=2.0.3
  Using cached mistune-2.0.5-py2.py3-none-any.whl (24 kB)
Collecting defusedxml
  Using cached defusedxml-0.7.1-py2.py3-none-any.whl (25 kB)
Collecting nbclient>=0.5.0
  Using cached nbclient-0.7.2-py3-none-any.whl (71 kB)
Requirement already satisfied: markupsafe>=2.0 in d:\program files\python\python38\lib\site-packages (from nbconvert->jupyter==1.0.0->d2l) (2.1.2)
Requirement already satisfied: jinja2>=3.0 in d:\program files\python\python38\lib\site-packages (from nbconvert->jupyter==1.0.0->d2l) (3.1.2)
Collecting nbformat>=5.1
  Using cached nbformat-5.8.0-py3-none-any.whl (77 kB)
Collecting bleach
  Using cached bleach-6.0.0-py3-none-any.whl (162 kB)
Collecting importlib-metadata>=3.6
  Using cached importlib_metadata-6.1.0-py3-none-any.whl (21 kB)
Collecting jupyterlab-pygments
  Using cached jupyterlab_pygments-0.2.2-py2.py3-none-any.whl (21 kB)
Collecting beautifulsoup4
  Using cached beautifulsoup4-4.12.0-py3-none-any.whl (132 kB)
Collecting tinycss2
  Using cached tinycss2-1.2.1-py3-none-any.whl (21 kB)
Collecting pandocfilters>=1.4.1
  Using cached pandocfilters-1.5.0-py2.py3-none-any.whl (8.7 kB)
Collecting Send2Trash>=1.8.0
  Using cached Send2Trash-1.8.0-py3-none-any.whl (18 kB)
Collecting argon2-cffi
  Using cached argon2_cffi-21.3.0-py3-none-any.whl (14 kB)
Collecting ipython-genutils
  Using cached ipython_genutils-0.2.0-py2.py3-none-any.whl (26 kB)
Collecting terminado>=0.8.3
  Using cached terminado-0.17.1-py3-none-any.whl (17 kB)
Collecting nbclassic>=0.4.7
  Using cached nbclassic-0.5.3-py3-none-any.whl (10.0 MB)
Collecting prometheus-client
  Using cached prometheus_client-0.16.0-py3-none-any.whl (122 kB)
Collecting qtpy>=2.0.1
  Downloading QtPy-2.3.0-py3-none-any.whl (83 kB)
     ---------------------------------------- 83.6/83.6 kB 68.0 kB/s eta 0:00:00
Collecting zipp>=0.5
  Using cached zipp-3.15.0-py3-none-any.whl (6.8 kB)
Collecting jedi>=0.16
  Using cached jedi-0.18.2-py2.py3-none-any.whl (1.6 MB)
Collecting decorator
  Using cached decorator-5.1.1-py3-none-any.whl (9.1 kB)
Collecting backcall
  Using cached backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Collecting pickleshare
  Using cached pickleshare-0.7.5-py2.py3-none-any.whl (6.9 kB)
Collecting colorama
  Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting stack-data
  Using cached stack_data-0.6.2-py3-none-any.whl (24 kB)
Collecting python-dateutil>=2.7
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting pywin32>=300
  Using cached pywin32-305-cp38-cp38-win_amd64.whl (12.3 MB)
Collecting platformdirs>=2.5
  Using cached platformdirs-3.1.1-py3-none-any.whl (14 kB)
Collecting notebook-shim>=0.1.0
  Downloading notebook_shim-0.2.2-py3-none-any.whl (13 kB)
Collecting jupyter-server>=1.8
  Downloading jupyter_server-2.5.0-py3-none-any.whl (366 kB)
     ---------------------------------------- 366.8/366.8 kB 99.2 kB/s eta 0:00:00
Collecting fastjsonschema
  Downloading fastjsonschema-2.16.3-py3-none-any.whl (23 kB)
Collecting jsonschema>=2.6
  Downloading jsonschema-4.17.3-py3-none-any.whl (90 kB)
     ---------------------------------------- 90.4/90.4 kB 59.0 kB/s eta 0:00:00
Collecting wcwidth
  Downloading wcwidth-0.2.6-py2.py3-none-any.whl (29 kB)
Collecting pywinpty>=1.1.0
  Downloading pywinpty-2.0.10-cp38-none-win_amd64.whl (1.4 MB)
     ---------------------------------------- 1.4/1.4 MB 65.5 kB/s eta 0:00:00
Collecting argon2-cffi-bindings
  Downloading argon2_cffi_bindings-21.2.0-cp36-abi3-win_amd64.whl (30 kB)
Collecting soupsieve>1.2
  Downloading soupsieve-2.4-py3-none-any.whl (37 kB)
Collecting webencodings
  Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting parso<0.9.0,>=0.8.0
  Downloading parso-0.8.3-py2.py3-none-any.whl (100 kB)
     ---------------------------------------- 100.8/100.8 kB 165.5 kB/s eta 0:00:00
Collecting importlib-resources>=1.4.0
  Downloading importlib_resources-5.12.0-py3-none-any.whl (36 kB)
Collecting pkgutil-resolve-name>=1.3.10
  Downloading pkgutil_resolve_name-1.3.10-py3-none-any.whl (4.7 kB)
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0
  Downloading pyrsistent-0.19.3-cp38-cp38-win_amd64.whl (62 kB)
     ---------------------------------------- 62.7/62.7 kB 108.4 kB/s eta 0:00:00
Collecting attrs>=17.4.0
  Downloading attrs-22.2.0-py3-none-any.whl (60 kB)
     ---------------------------------------- 60.0/60.0 kB 40.3 kB/s eta 0:00:00
Collecting jupyter-server-terminals
  Downloading jupyter_server_terminals-0.4.4-py3-none-any.whl (13 kB)
Collecting anyio>=3.1.0
  Downloading anyio-3.6.2-py3-none-any.whl (80 kB)
     ---------------------------------------- 80.6/80.6 kB 73.9 kB/s eta 0:00:00
Collecting jupyter-events>=0.4.0
  Downloading jupyter_events-0.6.3-py3-none-any.whl (18 kB)
Collecting websocket-client
  Downloading websocket_client-1.5.1-py3-none-any.whl (55 kB)
     ---------------------------------------- 55.9/55.9 kB 48.7 kB/s eta 0:00:00
Collecting cffi>=1.0.1
  Downloading cffi-1.15.1-cp38-cp38-win_amd64.whl (178 kB)
     ---------------------------------------- 178.8/178.8 kB 82.4 kB/s eta 0:00:00
Collecting executing>=1.2.0
  Downloading executing-1.2.0-py2.py3-none-any.whl (24 kB)
Collecting asttokens>=2.1.0
  Downloading asttokens-2.2.1-py2.py3-none-any.whl (26 kB)
Collecting pure-eval
  Downloading pure_eval-0.2.2-py3-none-any.whl (11 kB)
Collecting sniffio>=1.1
  Downloading sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     ---------------------------------------- 118.7/118.7 kB 83.6 kB/s eta 0:00:00
Collecting pyyaml>=5.3
  Downloading PyYAML-6.0-cp38-cp38-win_amd64.whl (155 kB)
     ---------------------------------------- 155.4/155.4 kB 103.3 kB/s eta 0:00:00
Collecting rfc3339-validator
  Downloading rfc3339_validator-0.1.4-py2.py3-none-any.whl (3.5 kB)
Collecting python-json-logger>=2.0.4
  Downloading python_json_logger-2.0.7-py3-none-any.whl (8.1 kB)
Collecting rfc3986-validator>=0.1.1
  Downloading rfc3986_validator-0.1.1-py2.py3-none-any.whl (4.2 kB)
Collecting jsonpointer>1.13
  Downloading jsonpointer-2.3-py2.py3-none-any.whl (7.8 kB)
Collecting uri-template
  Downloading uri_template-1.2.0-py3-none-any.whl (10 kB)
Collecting fqdn
  Downloading fqdn-1.5.1-py3-none-any.whl (9.1 kB)
Collecting isoduration
  Downloading isoduration-20.11.0-py3-none-any.whl (11 kB)
Collecting webcolors>=1.11
  Downloading webcolors-1.12-py3-none-any.whl (9.9 kB)
Collecting arrow>=0.15.0
  Downloading arrow-1.2.3-py3-none-any.whl (66 kB)
     ---------------------------------------- 66.4/66.4 kB 128.5 kB/s eta 0:00:00
Installing collected packages: webencodings, wcwidth, Send2Trash, pywin32, pure-eval, pickleshare, mistune, ipython-genutils, fastjsonschema, executing, backcall, zipp, widgetsn
bextension, websocket-client, webcolors, uri-template, traitlets, tornado, tinycss2, soupsieve, sniffio, rfc3986-validator, rfc3339-validator, pyzmq, pyyaml, pywinpty, python-js
on-logger, python-dateutil, pyrsistent, pygments, pycparser, psutil, prompt-toolkit, prometheus-client, platformdirs, pkgutil-resolve-name, parso, pandocfilters, packaging, nump
y, nest-asyncio, jupyterlab-widgets, jupyterlab-pygments, jsonpointer, idna, fqdn, fonttools, defusedxml, decorator, debugpy, colorama, chardet, bleach, attrs, asttokens, termin
ado, stack-data, requests, qtpy, pandas, matplotlib-inline, matplotlib, jupyter-core, jedi, importlib-resources, importlib-metadata, comm, cffi, beautifulsoup4, arrow, anyio, ju
pyter-server-terminals, jupyter-client, jsonschema, isoduration, ipython, argon2-cffi-bindings, nbformat, ipywidgets, ipykernel, argon2-cffi, qtconsole, nbclient, jupyter-events
, jupyter-console, nbconvert, jupyter-server, notebook-shim, nbclassic, notebook, jupyter, d2l
  Attempting uninstall: python-dateutil
    Found existing installation: python-dateutil 2.8.1
    Uninstalling python-dateutil-2.8.1:
      Successfully uninstalled python-dateutil-2.8.1
  Attempting uninstall: numpy
    Found existing installation: numpy 1.23.4
    Uninstalling numpy-1.23.4:
      Successfully uninstalled numpy-1.23.4
  Attempting uninstall: idna
    Found existing installation: idna 3.3
    Uninstalling idna-3.3:
      Successfully uninstalled idna-3.3
  Attempting uninstall: requests
    Found existing installation: requests 2.28.1
    Uninstalling requests-2.28.1:
      Successfully uninstalled requests-2.28.1
  Attempting uninstall: pandas
    Found existing installation: pandas 1.2.1
    Uninstalling pandas-1.2.1:
      Successfully uninstalled pandas-1.2.1
  Attempting uninstall: matplotlib
    Found existing installation: matplotlib 3.4.3
    Uninstalling matplotlib-3.4.3:
      Successfully uninstalled matplotlib-3.4.3
Successfully installed Send2Trash-1.8.0 anyio-3.6.2 argon2-cffi-21.3.0 argon2-cffi-bindings-21.2.0 arrow-1.2.3 asttokens-2.2.1 attrs-22.2.0 backcall-0.2.0 beautifulsoup4-4.12.0
bleach-6.0.0 cffi-1.15.1 chardet-4.0.0 colorama-0.4.6 comm-0.1.3 d2l-0.17.6 debugpy-1.6.6 decorator-5.1.1 defusedxml-0.7.1 executing-1.2.0 fastjsonschema-2.16.3 fonttools-4.39.2
 fqdn-1.5.1 idna-2.10 importlib-metadata-6.1.0 importlib-resources-5.12.0 ipykernel-6.22.0 ipython-8.11.0 ipython-genutils-0.2.0 ipywidgets-8.0.5 isoduration-20.11.0 jedi-0.18.2
 jsonpointer-2.3 jsonschema-4.17.3 jupyter-1.0.0 jupyter-client-8.1.0 jupyter-console-6.6.3 jupyter-core-5.3.0 jupyter-events-0.6.3 jupyter-server-2.5.0 jupyter-server-terminals
-0.4.4 jupyterlab-pygments-0.2.2 jupyterlab-widgets-3.0.6 matplotlib-3.5.1 matplotlib-inline-0.1.6 mistune-2.0.5 nbclassic-0.5.3 nbclient-0.7.2 nbconvert-7.2.10 nbformat-5.8.0 n
est-asyncio-1.5.6 notebook-6.5.3 notebook-shim-0.2.2 numpy-1.21.5 packaging-23.0 pandas-1.2.4 pandocfilters-1.5.0 parso-0.8.3 pickleshare-0.7.5 pkgutil-resolve-name-1.3.10 platf
ormdirs-3.1.1 prometheus-client-0.16.0 prompt-toolkit-3.0.38 psutil-5.9.4 pure-eval-0.2.2 pycparser-2.21 pygments-2.14.0 pyrsistent-0.19.3 python-dateutil-2.8.2 python-json-logg
er-2.0.7 pywin32-305 pywinpty-2.0.10 pyyaml-6.0 pyzmq-25.0.2 qtconsole-5.4.1 qtpy-2.3.0 requests-2.25.1 rfc3339-validator-0.1.4 rfc3986-validator-0.1.1 sniffio-1.3.0 soupsieve-2
.4 stack-data-0.6.2 terminado-0.17.1 tinycss2-1.2.1 tornado-6.2 traitlets-5.9.0 uri-template-1.2.0 wcwidth-0.2.6 webcolors-1.12 webencodings-0.5.1 websocket-client-1.5.1 widgets
nbextension-4.0.6 zipp-3.15.0

不过全部下完后就没事了,可以正常运行。

可能有警告:

这是由于卸载或者更新旧版本时,未能删掉对应的.dll文件导致的

解决: 根据警告路径,找到对应的dll文件,根据时间,删掉之前的版本,保留近期版本,直接删除并不会影响新版本。

3.  d2l.plt.scatter(...)报错

Colab上

 出现以上问题的原因是matplotlib版本过高,将高版本的matplotlib卸载,安装低版本的matplotlib即可。

当前d2l包的版本是d2l 2.0.0b0,推荐使用安装matplotlib ==3.0.0 (版本查看可使用pip list命令)

安装命令如下:

!pip install matplotlib==3.0.0

还可能有报错:

这个问题未解决,只能重开一个colab笔记本,在一开始使用命令!pip install d2l==0.15.,然后照着沐神的代码写就行了

4. 源码拉取

(自己本地的pycharm上)

GitHub上李沐大神的代码:https://github.com/Miraclelucy/dive_into_deep_learning

或这个:https://github.com/ShusenTang/Dive-into-DL-PyTorch/tree/master/code

可以从这里直接下载d2l:

 将下载好的文件夹 d2l 放到自己创建的环境下即可;
可以通过指令numpy.__file__查找numpy所在环境路径,将下载好的d2l也放到该路径中的site-packages文件夹下即可。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值