我正在使用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有关?
答案 0 :(得分:0)
在您的
python setup.py py2app
或
python3 setup.py py2app
包括标志--packages=PIL
答案 1 :(得分:0)
为libpeg
安装动态库
brew install libjpeg
应该解决这个问题,但是我仍然遇到其他依赖项,例如zlib
和openjpeg
。但是自己编译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