我在跟踪一个Tensorflow图像分类教程。在运行以下代码时-
import PIL
import tensorflow as tf
from tensorflow import keras
sunflower_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/592px-Red_sunflower.jpg"
sunflower_path = tf.keras.utils.get_file('Red_sunflower', origin=sunflower_url)
img = keras.preprocessing.image.load_img(sunflower_path, target_size=(180, 180))我在最后一行收到以下错误。
ImportError: Could not import PIL.Image. The use of `load_img` requires PIL.我怎样才能解决上述问题?
请注意,我有枕头安装在我的conda工作环境(python=3.8,Tensorflow=2.3)。
发布于 2021-04-16 17:20:12
错误说明您的机器上没有安装pillow。如果你用的是康达,那你就得做
conda install pillow如果你不使用康达,那我就试试
pip install pillow编辑1:如果您已经在conda中安装了PIL,请尝试
conda uninstall PIL
conda install Pillow编辑2:如果您的env中安装了一个与TensorFlow/Keras版本不兼容的旧版本的Pillow,那么重新安装Pillow可能会有帮助。
https://stackoverflow.com/questions/67129554
复制相似问题