0

I'm having an issue with my tensorflow on windows 10 (python 3.7, tf 2.1.0, keras 2.3.1, pillow 7.1.1). I had some code I wrote on an osx machine and was porting over to windows. I am using conda envs and have all the necessary packages installed (tensorflow, keras, pillow, opencv, etc) but I am getting the following error

Traceback (most recent call last):
...
"...\venv\lib\site-packages\keras_preprocessing\image\utils.py", line 108, in load_img
    raise ImportError('Could not import PIL.Image. '
ImportError: Could not import PIL.Image. The use of `load_img` requires PIL.

I have tried reinstalling pillow, tensorflow, keras, creating a new environment, installing with pip and repeated this in about every location I can think of but this issue remains persistent. Any help would be greatly appreciated.

Thank you

eug.2142
  • 19
  • 2

1 Answers1

0

One solution that might work for your case:

First, you need to : pip install pillow (uninstall + reinstall / upgrade it it's the case)

Second, you need to change your imports in this way:

from IPython.display import display
from PIL import Image

This solution can be found in the following thread:

ImportError: Could not import the Python Imaging Library (PIL) required to load image files on tensorflow

Timbus Calin
  • 13,809
  • 5
  • 41
  • 59
  • Hi, thanks for your reply. I have pillow installed (pip show pillow) and have tried uninstalling and reinstalling both using pip and in a conda env. I don't use the display function so I'm not sure why I need to import it? The error is occuring in a file that comes with Keras, its not anything I wrote. – eug.2142 Apr 13 '20 at 19:12
  • I saw that post earlier but what was tried there didn't solve the error. – eug.2142 Apr 13 '20 at 19:15
  • Please use tensorflow inside Keras rather than Keras alone. Replace all your imports to "from tensorflow.keras" – Timbus Calin Apr 14 '20 at 06:09