【问题标题】:Tensorflow import error when loading PIL (pillow)加载PIL(枕头)时的Tensorflow导入错误
【发布时间】:2020-04-13 04:17:22
【问题描述】:

我在 Windows 10(python 3.7、tf 2.1.0、keras 2.3.1、pillow 7.1.1)上的 tensorflow 出现问题。我有一些我在 osx 机器上编写的代码,并且正在移植到 Windows。我正在使用 conda envs 并安装了所有必要的包(tensorflow、keras、pillow、opencv 等),但我收到以下错误

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.

我尝试重新安装枕头、张量流、keras,创建一个新环境,使用 pip 安装并在我能想到的几乎每个位置重复此操作,但这个问题仍然存在。任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 能分享一下环境的内容,你是怎么创建的等等吗?

标签: python tensorflow keras python-imaging-library


【解决方案1】:

一种可能适用于您的情况的解决方案:

首先,你需要:pip install pillow(卸载+重新安装/升级就是这样)

其次,您需要以这种方式更改导入:

from IPython.display import display
from PIL import Image

这个解决方案可以在以下线程中找到:

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

【讨论】:

  • 您好,感谢您的回复。我已经安装了枕头(pip show 枕头),并尝试使用 pip 和 conda env 卸载和重新安装。我不使用显示功能所以我不确定为什么需要导入它?错误发生在 Keras 附带的文件中,不是我写的任何东西。
  • 我之前看到过那个帖子,但在那里尝试的方法并没有解决错误。
  • 请在 Keras 中使用 tensorflow,而不是单独使用 Keras。将所有导入替换为“来自 tensorflow.keras”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-03
  • 1970-01-01
  • 1970-01-01
  • 2021-02-05
相关资源
最近更新 更多