启动应用程序时出现Py2App PIL图像错误

3
我正在使用py2app将一个Python文件转换为应用程序,但遇到了以下错误:
Traceback (most recent call last):
  File "/Users/MYUSER/PycharmProjects/webstuff/BotTest/dist/ws1.app/Contents/Resources/__boot__.py", line 87, in _recipes_pil_prescript
    import Image
ModuleNotFoundError: No module named 'Image'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/MYUSER/PycharmProjects/webstuff/BotTest/dist/ws1.app/Contents/Resources/__boot__.py", line 132, in <module>
    _recipes_pil_prescript(['ImtImagePlugin', 'XpmImagePlugin', 'FtexImagePlugin', 'McIdasImagePlugin', 'MpegImagePlugin', 'SpiderImagePlugin', 'DdsImagePlugin', 'FpxImagePlugin', 'MspImagePlugin', 'XVThumbImagePlugin', 'GbrImagePlugin', 'MpoImagePlugin', 'BmpImagePlugin', 'BlpImagePlugin', 'IptcImagePlugin', 'PpmImagePlugin', 'JpegImagePlugin', 'SgiImagePlugin', 'PalmImagePlugin', 'PsdImagePlugin', 'ImImagePlugin', 'MicImagePlugin', 'BufrStubImagePlugin', 'WebPImagePlugin', 'FliImagePlugin', 'TgaImagePlugin', 'PixarImagePlugin', 'TiffImagePlugin', 'CurImagePlugin', 'PngImagePlugin', 'FitsStubImagePlugin', 'Hdf5StubImagePlugin', 'DcxImagePlugin', 'IcnsImagePlugin', 'EpsImagePlugin', 'GifImagePlugin', 'SunImagePlugin', 'WmfImagePlugin', 'GribStubImagePlugin', 'PcdImagePlugin', 'IcoImagePlugin', 'XbmImagePlugin', 'PdfImagePlugin', 'PcxImagePlugin', 'Jpeg2KImagePlugin'])
  File "/Users/MYUSER/PycharmProjects/webstuff/BotTest/dist/ws1.app/Contents/Resources/__boot__.py", line 90, in _recipes_pil_prescript
    from PIL import Image
  File "PIL/Image.pyc", line 64, in <module>
  File "PIL/_imaging.pyc", line 14, in <module>
  File "PIL/_imaging.pyc", line 10, in __load
  File "imp.pyc", line 342, in load_dynamic
ImportError: dlopen(/Users/MYUSER/PycharmProjects/webstuff/BotTest/dist/ws1.app/Contents/Resources/lib/python3.7/lib-dynload/PIL/_imaging.so, 2): Library not loaded: @loader_path/.dylibs/libjpeg.9.dylib
  Referenced from: /Users/MYUSER/PycharmProjects/webstuff/BotTest/dist/ws1.app/Contents/Resources/lib/python3.7/lib-dynload/PIL/_imaging.so
  Reason: image not found

在出现错误后,程序将被终止。程序中使用的所有图像都是通过设置中的data_files包含的。我的代码有错误吗?还是与py2app有关?

这个问题解决了吗?我现在也遇到了同样的问题。 - Ted Cost
2个回答

5
在您的
python setup.py py2app

或者

python3 setup.py py2app

包括标志--packages=PIL


1
安装动态库libpeg
brew install libjpeg

虽然应该解决了这个问题,但我仍然遇到了其他依赖项,例如zlibopenjpeg。但是自己编译Pillow可以解决这个问题。

git clone git@github.com:python-pillow/Pillow.git
brew install jpeg
brew install openjpeg
brew install zlib
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
cd Pillow
python setup.py install

这里是摘要:
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version      Pillow 7.2.0.dev0
platform     darwin 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
             [Clang 6.0 (clang-600.0.57)]
--------------------------------------------------------------------
--- JPEG support available
--- OPENJPEG (JPEG2000) support available (2.3)
--- ZLIB (PNG/ZIP) support available
*** LIBIMAGEQUANT support not available
--- LIBTIFF support available
--- FREETYPE2 support available
--- LITTLECMS2 support available
*** WEBP support not available
*** WEBPMUX support not available
--- XCB (X protocol) support available
--------------------------------------------------------------------
To add a missing option, make sure you have the required

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接