一、问题描述
前段时间在学习李沐老师的动手学深度学习课程,但是由于之前对于计算机相关知识基础不牢固,才学到第二章就被一个问题难住了。
报错代码如下:
%matplotlib inline
import numpy as np
from matplotlib_inline import backend_inline
from d2l import torch as d2l
def f(x):
return 3 * x ** 2 - 4 * x
报错提示:
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 4
2 import numpy as np
3 from matplotlib_inline import backend_inline
----> 4 from d2l import torch as d2l
7 def f(x):
8 return 3 * x ** 2 - 4 * x
ModuleNotFoundError: No module named 'd2l'
一开始我以为是不是书中将虚拟环境、包和库函数的名称都命名为“d2l”导致冲突,所以另开了个新的虚拟环境运行,但仍然报相同的错误。在网上找了一些解答也没法解决。
后来终于意识到哪里出现了错误,原来是因为我是用的jupyter lab编译环境,除了要有虚拟环境,还需要将其关联到 Jupyter 内核。
意识到这点,问题就很好解决了。
二、解决方案
ipykernel
是一个 Python 库&#