I want to use from torchvision import transforms
but there’s an error that says like this
{
"name": "ImportError",
"message": "cannot import name 'Image' from 'PIL' (unknown location)",
"stack": "---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/tmp/ipykernel_2889/3247709967.py in <module>
4 from torch import optim
5 from torch.utils.data import Dataset, DataLoader
----> 6 from torchvision import transforms
7 from torchvision.models import resnet18, ResNet18_Weights
8 from torchvision.datasets import ImageFolder
~/miniconda3/envs/pretrain-dynamic-vit/lib/python3.7/site-packages/torchvision/__init__.py in <module>
3
4 import torch
----> 5 from torchvision import datasets, io, models, ops, transforms, utils
6
7 from .extension import _HAS_OPS
~/miniconda3/envs/pretrain-dynamic-vit/lib/python3.7/site-packages/torchvision/datasets/__init__.py in <module>
----> 1 from ._optical_flow import FlyingChairs, FlyingThings3D, HD1K, KittiFlow, Sintel
2 from ._stereo_matching import (
3 CarlaStereo,
4 CREStereo,
5 ETH3DStereo,
~/miniconda3/envs/pretrain-dynamic-vit/lib/python3.7/site-packages/torchvision/datasets/_optical_flow.py in <module>
7 import numpy as np
8 import torch
----> 9 from PIL import Image
10
11 from ..io.image import _read_png_16
ImportError: cannot import name 'Image' from 'PIL' (unknown location)"
}
Which from my reading.. it means the torchvision import transforms cannot see the package PIL to import Image
PIL or is said to be outdated in this question import-error-no-modul-named-pil-question, so I reinstall PIL and change the name of the packaged into PIllow as suggested by the answer. But the package, from torchvision import transforms
still cannot detect the already installed Pillow. What to do? Is there like dependency clause I should change somewhere?
I have tried reinstalling the package, and simple commands from conda list Pillow
shown this
~/miniconda3/envs/pretrain-dynamic-vit/lib/python3.7/site-packages/torchvision/datasets$ conda list Pillow
# packages in environment at /home/sean/miniconda3/envs/pretrain-dynamic-vit:
#
# Name Version Build Channel
pillow 9.5.0 pypi_0 pypi
It exists, but the package cannot sees it somehow? The python version is 3.7.12. How to look for ‘does this package exist in this version of this library but not the older/newer version of this library’? since the documentation of torchvision doesn’t say anything about it it seems?