问题描述
我正在阅读《用R进行深度学习》一书的第5章( https://livebook.manning.com/book/deep-learning-with-r/chapter-5/112 ).
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).
运行下面的代码时,出现以下错误:Error in py_iter_next(it, completed) : ImportError: Could not import PIL.Image. The use of load_img requires PIL.
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.
有关此错误消息的所有答案,建议使用pip install pillow
.当我在终端中运行此程序时,将显示以下内容:
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)
因此,已经安装了Pillow,但是我无法运行下面的代码.我正在使用Mac Book Pro平台x86_64-apple-darwin15.6.0以及R版本3.6.0(2019-04-26).我的机器上也安装了Python 3.7.3.任何推荐和支持都将受到高度赞赏!
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)
推荐答案
问题是Keras for R创建了自己的虚拟环境,称为r-reticulate
,并且在那里缺少了枕头.您还必须找出它是使用conda还是virtualenv创建此类环境的.然后,激活它并安装枕头和scipy.最后,重新启动R会话.
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.
在我的情况下是conda:
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
这篇关于即使已经安装了枕头,也无法导入PIL.Image吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!