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.