%matplotlib inline#该项事实也无法运行
from d2l import torch as d2l#此行报错如下所示
点击查看代码
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[89], line 1
----> 1 from d2l import torch as d2l
File E:\DeepLearning\anaconda3\envs\D2L-pytorch\lib\site-packages\d2l\torch.py:6
4 import numpy as np
5 import torch
----> 6 import torchvision
7 from PIL import Image
8 from torch import nn
File E:\DeepLearning\anaconda3\envs\D2L-pytorch\lib\site-packages\torchvision\__init__.py:5
2 import warnings
4 import torch
----> 5 from torchvision import datasets
6 from torchvision import io
7 from torchvision import models
File E:\DeepLearning\anaconda3\envs\D2L-pytorch\lib\site-packages\torchvision\datasets\__init__.py:1
----> 1 from ._optical_flow import KittiFlow, Sintel, FlyingChairs, FlyingThings3D, HD1K
2 from .caltech import Caltech101, Caltech256
3 from .celeba import CelebA
File E:\DeepLearning\anaconda3\envs\D2L-pytorch\lib\site-packages\torchvision\datasets\_optical_flow.py:10
8 import numpy as np
9 import torch
---> 10 from PIL import Image
12 from ..io.image import _read_png_16
13 from .utils import verify_str_arg
File E:\DeepLearning\anaconda3\envs\D2L-pytorch\lib\site-packages\PIL\Image.py:82
73 MAX_IMAGE_PIXELS = int(1024 * 1024 * 1024 // 4 // 3)
76 try:
77 # If the _imaging C module is not present, Pillow will not load.
78 # Note that other modules should not refer to _imaging directly;
79 # import Image and use the Image.core variable instead.
80 # Also note that Image.core is not a publicly documented interface,
81 # and should be considered private and subject to change.
---> 82 from . import _imaging as core
84 if __version__ != getattr(core, "PILLOW_VERSION", None):
85 msg = (
86 "The _imaging extension was built for another version of Pillow or PIL:\n"
87 f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
88 f"Pillow version: {__version__}"
89 )
ImportError: DLL load failed while importing _imaging: 找不到指定的模块。
现有环境:pillow10.0.0,python3.9,torch1.12,cuda11.8
处理方式:
先卸载原有pillow版本
pip uninstall pillow
再安装老版本的pillow
pip install pillow==9.0