深度学习时候d2l报错和使用问题

目录

报错

解决:

使用:


解决AttributeError: module 'd2l.torch' has no attribute 'load_data_time_machine'_attributeerror: module 'torch' has no attribute 'l-CSDN博客文章浏览阅读5.5k次,点赞8次,收藏3次。文章描述了在使用D2L库时遇到的AttributeError,原因在于使用的d2l版本过高。解决方法是通过pip将d2l降级到0.17.5版本。https://blog.csdn.net/Rhett_Butler0922/article/details/137793716?fromshare=blogdetail&sharetype=blogdetail&sharerId=137793716&sharerefer=PC&sharesource=qq_52122048&sharefrom=from_link解决AttributeError: module 'd2l.torch' has no attribute 'load_data_time_machine'_attributeerror: module 'torch' has no attribute 'l-CSDN博客

报错

【d2l包】关于李沐《动手学深度学习》中的attributeerror: module 'd2l.torch' has no attribute 'train_ch3'问题_d2l.train_ch3报错-爱代码爱编程https://icode.best/i/554672373555637

【d2l包】关于李沐《动手学深度学习》中的attributeerror: module 'd2l.torch' has no attribute 'train_ch3'问题_d2l.train_ch3报错-爱代码爱编程

d2l相当于一个收集函数的包,只要在一个py文件中定义函数def func():时在冒号后加上了注释#@save,那就可以在另一个任意路径的py文件下以d2l.pytorch.func调用这个函数。

解决:

我的:

或者

复制代码
(E:\deeplearning202604) C:\Users\Lenovo>python -c "import d2l; print(d2l.__version__)"
1.0.3

(E:\deeplearning202604) C:\Users\Lenovo>
项目 信息
PyPI 包名 d2l(即 pip install d2l
稳定版本 0.17.6(官方配套书版)
最低推荐版本 0.17.5(低于此版缺失 d2l.Image等 API)
安装命令 pip install d2l==0.17.6
复制代码
(E:\deeplearning202604) C:\Users\Lenovo>python --version
Python 3.9.25

(E:\deeplearning202604) C:\Users\Lenovo>

(E:\deeplearning202604) C:\Users\Lenovo>python -c "import torch; print(torch.__version__); print(torch.cuda.is_available())"
2.6.0+cu126
True

1. 只装 d2l 本体,不装任何依赖(torch、numpy 等都不动)否则会自动修改python和torch等版本

pip install d2l==0.17.5 --no-deps

python 复制代码
(E:\deeplearning202604) C:\Users\Lenovo>pip install d2l==0.17.5 --no-deps
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting d2l==0.17.5
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6a/be/eb453dbdd80d0563e2a6dac4aff8b76b0c24641d20b05e85b560f90282f9/d2l-0.17.5-py3-none-any.whl (82 kB)
Installing collected packages: d2l
  Attempting uninstall: d2l
    Found existing installation: d2l 1.0.3
    Uninstalling d2l-1.0.3:
      Successfully uninstalled d2l-1.0.3
Successfully installed d2l-0.17.5

(E:\deeplearning202604) C:\Users\Lenovo>python -c "import d2l; print(d2l.__version__)"
0.17.5

(E:\deeplearning202604) C:\Users\Lenovo>python -c "import torch; print(torch.__version__)"
2.6.0+cu126

使用:

自己也可以创建一个类似d2l这样子的模块

要点 说明
不要与 Python 内置名称冲突 比如别注册一个叫 list的函数,否则会把原生的 list覆盖掉。
模块热更新 如果在 Jupyter 里修改了 mylib.py,需要 import importlib; importlib.reload(mylib)才能生效。
跨项目共享 mylib.py放到项目根目录,或者做成 pip 包,就能到处用了。
相关推荐
机器之心2 小时前
Anthropic发现Claude「类意识工作台」!神秘J空间藏着没说出口的想法
人工智能·openai
AI实践录2 小时前
大模型架构:理解大模型预测输出文本的底层逻辑
人工智能
Lifangyun_WD2 小时前
昇腾910B vs NVIDIA A100/H100:国产GPU算力租赁选型与迁移实践
人工智能·gpu算力·ai算力·算力租赁·gpu云主机
卡卡罗特AI2 小时前
GPT5.6 今晚全量开发?Codex上线史上最强Coding模型!
人工智能·ai编程
某林2122 小时前
从硬件解耦、3D公差设计到ROS 2柔性导航
人工智能·3d·机器人·ros2·技术复盘
字节跳动视频云技术团队2 小时前
AI Agent 会自己选 CDN 了:当网站访问者从 “人” 扩展到 “AI”,内容分发已升级
人工智能·cdn
机器之心2 小时前
世界模型太慢?西交大提出Fast LeWorldModel:用「动作前缀并行预测」让动态估计加速4倍
人工智能·openai
机器之心2 小时前
今天,「空间原生」时代正式到来!
人工智能·openai
MicrosoftReactor2 小时前
技术速递|Token 经济学:智能体 AI 时代的新 FinOps
人工智能·ai·agent·token·finops
阿里云大数据AI技术3 小时前
AI Search × ES Agent Builder 最佳实践:企业智能助手落地指南
人工智能·elasticsearch