py2exe中的PIL: '没有名为Image的模块

0 投票
1 回答
1318 浏览
提问于 2025-05-01 14:50

我有一个能正常工作的Python脚本,其中成功导入了Pillow库里的Image模块。

像这样使用:'from PIL import Image'

但是在使用py2exe把Pillow和其他库一起打包时,出现了以下错误:

'没有名为Image的模块'

其他的库似乎都能正常工作。

我已经找到这个解决方案:http://www.py2exe.org/index.cgi/py2exeAndPIL

但这个方法似乎没有解决我的问题。有没有其他方法可以告诉py2exe把'Image'和Pillow里需要的其他部分一起打包进去呢?

提前谢谢你,
Nico

暂无标签

1 个回答

0

你可以在py2exe的设置选项中添加PIL,可以放在packages或者includes里:

setup (
  options = {"py2exe": {...
                        "packages": ["PIL"], # For everything
                        "includes": ["PIL.Image", # Or here for bits and pieces 
                                     "PIL.PngImagePlugin"]}},
  name="foo",
  ...
  )

撰写回答