PIL import issue when updated w/ torchvision or fastai conda channel


(Wayne Nixalo) #1

May be of interest to @jeremy

I found an odd import error that I don’t know if it’s due to fast.ai, pytorch, or pillow itself.

tldr: On CPU-based MacOS I get an ImportError when importing PIL.Image after installing/updating pillow either as a torchvision dependency or from the fastai conda channel. If I pip install pillow-simd I have no issues importing PIL.Image or the torchvision package that relies on it. I have not tested this in runtime yet though. No issues on a GPU Linux machine.


ImportError: The _imaging extension was built for another version of Pillow or PIL:

If I update torchvision via: conda install -c pytorch torchvision (in this case fresh, after debugging this issue for a while):

The following NEW packages will be INSTALLED:

    pillow:      4.3.0-py36h96fe3d5_1
    torchvision: 0.2.0-py36hf5eb7ec_1 pytorch

Proceed ([y]/n)?

OR if I ignore torchvision and try to install pillow from the fastai channel:
conda install -c fastai pillow:

The following NEW packages will be INSTALLED:

    pillow: 4.3.0-py36h96fe3d5_1

Proceed ([y]/n)?

IF I go ahead and install pillow either of these ways, when I later try to run from PIL import Image or import PIL.Image, I will get the following error:

/.../Miniconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py:78: RuntimeWarning: The _imaging extension was built for another version of Pillow or PIL:
Core version: 4.3.0
Pillow version: 4.3.0.post0
  warnings.warn(str(v), RuntimeWarning)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../Miniconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py", line 63, in <module>
    PILLOW_VERSION))
ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: 4.3.0
Pillow version: 4.3.0.post0

The first time I saw this was in a Jupyter Notebook, in this case same error, but just with the traceback to the Image import from PIL:

/.../Miniconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py:78: RuntimeWarning: The _imaging extension was built for another version of Pillow or PIL:
Core version: 4.3.0
Pillow version: 4.3.0.post0
  warnings.warn(str(v), RuntimeWarning)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

...
...
...

~/Miniconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py in <module>()
     61                           "Pillow version: %s" %
     62                           (getattr(core, 'PILLOW_VERSION', None),
---> 63                            PILLOW_VERSION))
     64 
     65 except ImportError as v:

ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: 4.3.0
Pillow version: 4.3.0.post0

Unfortunately, in trying to figure out what was going on, I forgot exactly how i triggered this in no the first place. I think I updated my environment via conda update -n fastai --all, though I’m not sure.

What’s odd is, PIL.__version__ is showing the correct version: 4.3.0.post0. The version from the working pillow-simd install is the same.

According to this stackexchange thread it may be a question of updating NumPy et all, but my env’s already up to date (I haven’t tried a fresh install).

I’ve had no issues on my GPU Linux machine. Not sure where I should post this, but I’m hoping it’ll be helpful to someone managing the packages, or dealing with this issue.

Also no I haven’t restarted my laptop yet… so there’s always that.


(Jeremy Howard) #2

I’d suggest removing pillow using conda and pip, and delete its install directory, and install from scratch from the default repo. I no longer suggest using the fastai channel pillow version, and its not in our environment.yml any more. We’ve switched to opencv for our transformations.


(Wayne Nixalo) #3

Hah, that’s how I got it working – deleting the folder in the env’s site-packages directory. Not sure if there was anywhere else, but it wasn’t installed in root, and it worked afterwards so…

Odd, I saw pillow in my fastai/environment.yml file… this is after a git pull. Well I’ll just clone the repo fresh then.


(Jeremy Howard) #4

Pillow is still there, but it’s coming from the default channel now.


(Wayne Nixalo) #5

Gotcha. Yep, just recloned fastai/fastai/, commented out the - cuda90 line in environment.yml and was able to build the environment on a CPU MacBook. Checked, and no issues.


#6

I have similar problem: ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: 5.1.0
Pillow version: 5.0.0

When I go to anaconda I see in env pillow 5.1.0
I am a beginner. Could you please be more specific how to solve it and where to delete (I used anaconda)