Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: Could not import PIL.Image. The use of load_img requires PIL #444

Closed
dkgaraujo opened this issue Nov 20, 2020 · 3 comments
Closed

Comments

@dkgaraujo
Copy link

Hi all,
I was running the following example from the RStudio TensorFlow page, without the only change being the setup of the environment: https://tensorflow.rstudio.com/tutorials/advanced/images/transfer-learning-hub/

However, midway the following error occurred:

ImportError: Could not import PIL.Image. The use of load_img requires PIL.

I am running on MacOS 11.0.1 with the Apple TensorFlow backend. My reticulate::py_config() returns the following result:

python:         /Users/douglasaraujo/tensorflow_macos_venv/bin/python
libpython:      /Users/douglasaraujo/opt/anaconda3/lib/libpython3.8.dylib
pythonhome:     /Users/douglasaraujo/opt/anaconda3:/Users/douglasaraujo/opt/anaconda3
version:        3.8.3 (default, Jul  2 2020, 11:26:31)  [Clang 10.0.0 ]
numpy:          /Users/douglasaraujo/tensorflow_macos_venv/lib/python3.8/site-packages/numpy
numpy_version:  1.18.5

NOTE: Python version was forced by use_python function

I installed Pillow with the following terminal code:

$ ~/tensorflow_macos_venv/bin/pip install Pillow

and I can confirm it works by the following terminal code:

$  ~/tensorflow_macos_venv/bin/python 3
>>> import PIL.Image
>>> # success

So I don't know what else I could do to address the ImportError mentioned at the beginning. Any pointer/helper is much appreciated.

@nickschurch
Copy link

Did you solve this?

@t-kalinowski
Copy link
Member

t-kalinowski commented Aug 10, 2023

The original issue was almost certainly due to reticulate loading the wrong python (note the mismatch between the python binary in a venv, and libpython and pythonhome being from a different, anaconda, python installation).

In any case, the latest version of reticulate (1.31) has updated python finding behavior, and the tensorFlow + keras packages have updated installation routines to match. This alone should now work:

remotes::install_github("rstudio/reticulate")
remotes::install_github("rstudio/tensorflow")
remotes::install_github("rstudio/keras")

reticulate::install_python()
keras::install_keras()
# restart the R session, cmd+shift+0 or ctrl+shift+F10
library(keras)
# everything should now work

@nickschurch
Copy link

yep, all working now. Just needed to reload the Rstudio R session after installing pillow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants