动手学深度学习v2(李沐2021版),from d2l import torch as d2l报错

 

%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: 找不到指定的模块。

该处错误是由于pillow版本太高导致的python版本不匹配导致的

现有环境:

pillow==10.0.0
python==3.9
torch==1.12
cuda==11.8

处理方式:
先卸载原有pillow版本
pip uninstall pillow
再安装老版本的pillow
pip install pillow==9.0

posted @ 2024-01-25 21:27  Vincent_1085  阅读(925)  评论(0)    收藏  举报