giotto-ai / giotto-deep

Deep learning made topological.
Other
80 stars 11 forks source link

ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' #103

Closed shamsvahid2 closed 2 years ago

shamsvahid2 commented 2 years ago

I got this error while importing DataLoaderBuilder.

To reproduce

  1. Just import DataLoaderBuilder as follows and see the error:

from gdeep.data.datasets.base_dataloaders import DataLoaderBuilder

Versions

Linux-5.4.188+-x86_64-with-glibc2.31 Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:58:50) [GCC 10.3.0] NumPy 1.23.1 SciPy 1.8.1 Joblib 1.1.0 Scikit-learn 1.1.1 Giotto-tda 0.5.1

Additional context

I tried downgrading to pillow 6.1 but got the following:

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - pillow=6.1 -> python[version='2.7.*|3.5.*|3.6.*|3.4.*']
  - pillow=6.1 -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']

Your python: python=3.9
matteocao commented 2 years ago

@shamsvahid2 The proper way to import (as specified by the __init__ files and in the examples) should be

from gdeep.data.datasets import DataLoaderBuilder

Do you get the same error in this case? Is there any particular reason why you where using your import lines?

shamsvahid2 commented 2 years ago

Getting the same error in case using: from gdeep.data.datasets import DataLoaderBuilder. No particular reason, just a copy from this example.

raphaelreinauer commented 2 years ago

Could you please provide the versions of Pillow before downgrading (and other installed packages) you are running? The error message indicates that Pillow version 6.1 is incompatible with python version 3.9.

Furthermore, please post the entire error message you get when importing DataLoaderBuilder.

shamsvahid2 commented 2 years ago

Sorry, I made a mistake and closed it wrongly. My problem remains still.

Regarding versions:

Linux-5.4.188+-x86_64-with-glibc2.31 Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:58:50) [GCC 10.3.0] NumPy 1.23.1 SciPy 1.8.1 Joblib 1.1.0 Scikit-learn 1.1.1 Giotto-tda 0.5.1 Pillow '9.2.0'

and entire error message is as follows:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 from gdeep.data.datasets import DataLoaderBuilder

File ~/giotto-deep/gdeep/data/datasets/__init__.py:5, in <module>
      3 from .dataset_cloud import DatasetCloud
      4 from ._data_cloud import _DataCloud
----> 5 from .build_datasets import DatasetBuilder, get_dataset
      6 from .base_dataloaders import DataLoaderBuilder, \
      7     AbstractDataLoaderBuilder
      8 from .dataset_for_image import ImageClassificationFromFiles

File ~/giotto-deep/gdeep/data/datasets/build_datasets.py:6, in <module>
      4 import torch
      5 from torch.utils.data import DataLoader, IterDataPipe, Dataset, MapDataPipe
----> 6 from torchvision import datasets
      7 from torchtext import datasets as textdatasets
      8 from .tori import ToriDataset

File ~/conda-envs/giotto-deep/lib/python3.9/site-packages/torchvision/__init__.py:2, in <module>
      1 from torchvision import models
----> 2 from torchvision import datasets
      3 from torchvision import transforms
      4 from torchvision import utils

File ~/conda-envs/giotto-deep/lib/python3.9/site-packages/torchvision/datasets/__init__.py:9, in <module>
      7 from .svhn import SVHN
      8 from .phototour import PhotoTour
----> 9 from .fakedata import FakeData
     10 from .semeion import SEMEION
     11 from .omniglot import Omniglot

File ~/conda-envs/giotto-deep/lib/python3.9/site-packages/torchvision/datasets/fakedata.py:3, in <module>
      1 import torch
      2 import torch.utils.data as data
----> 3 from .. import transforms
      6 class FakeData(data.Dataset):
      7     """A fake dataset that returns randomly generated images and returns them as PIL images
      8 
      9     Args:
   (...)
     19 
     20     """

File ~/conda-envs/giotto-deep/lib/python3.9/site-packages/torchvision/transforms/__init__.py:1, in <module>
----> 1 from .transforms import *

File ~/conda-envs/giotto-deep/lib/python3.9/site-packages/torchvision/transforms/transforms.py:17, in <module>
     14 import collections
     15 import warnings
---> 17 from . import functional as F
     19 if sys.version_info < (3, 3):
     20     Sequence = collections.Sequence

File ~/conda-envs/giotto-deep/lib/python3.9/site-packages/torchvision/transforms/functional.py:5, in <module>
      3 import sys
      4 import math
----> 5 from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
      6 try:
      7     import accimage

ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/home/jovyan/conda-envs/giotto-deep/lib/python3.9/site-packages/PIL/__init__.py)
raphaelreinauer commented 2 years ago

The issue seems to be related to torchvision (see https://stackoverflow.com/questions/59659146/could-not-import-pillow-version-from-pil). The error should be fixed for torchvision>=0.5.0. Could you please upgrade your torchvision version and check if the error persists?

shamsvahid2 commented 2 years ago

It is solved; thanks a-lot

raphaelreinauer commented 2 years ago

You're welcome :)