这个错误提示:
ImportError: No module named PIL
说明你运行的代码中用到了 PIL(Python Imaging Library),但你的 Python 环境里没有安装这个库。
解决办法
现在已经没有单独维护的 PIL 了,通常用的是它的升级版 Pillow,它是完全兼容 PIL 的替代品。
你可以通过 pip 安装 Pillow:
pip install Pillow
如果证书问题,可以用:
pip install Pillow --trusted-host pypi.org --trusted-host files.pythonhosted.org
或者用清华镜像 HTTP 源:
pip install Pillow -i http://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
安装完成后
运行的代码中导入模块应该是:
from PIL import Image
而不是直接 import PIL。