Could not import PIL.Image even if Pillow already installed?

笑着哭i 提交于 2021-02-08 11:06:17

问题


I'm going through chapter 5 of the book Deep Learning with R (https://livebook.manning.com/book/deep-learning-with-r/chapter-5/112).

When running the code below, the following error appears: Error in py_iter_next(it, completed) : ImportError: Could not import PIL.Image. The use of load_img requires PIL.

All answers with regard to this error message recommend using pip install pillow. When I run this in my Terminal, the following appears:

Requirement already satisfied: pillow in /anaconda3/lib/python3.7/site-packages (6.1.0)

Hence, Pillow is already installed, whereas I cannot run the code below. I'm working with a Mac Book Pro platform x86_64-apple-darwin15.6.0 as well as R version 3.6.0 (2019-04-26). I also have Python 3.7.3 installed on my machine. Any referrals and support are highly appreciated!

#Displaying a batch of data and labels
batch <- generator_next(train_generator)
str(batch)

回答1:


The problem is that Keras for R creates its own virtual environment, called r-reticulate, and pillow is missing in there. You also have to find out whether it used conda or virtualenv to create such environment. Then, activate it and install pillow and scipy. Finally, restart the R session.

In my case it was conda:

$ conda env list
# conda environments:
#
base                  *  C:\Users\black\Anaconda3
py2                      C:\Users\black\Anaconda3\envs\py2
r-reticulate             C:\Users\black\Anaconda3\envs\r-reticulate

$ conda activate r-reticulate
$ conda install pillow scipy


来源:https://stackoverflow.com/questions/57612703/could-not-import-pil-image-even-if-pillow-already-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!