Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: dynamic module does not define module export function (PyInit_PIL__imaging) in Xcode 15. #934

Open
Kryptonh opened this issue Aug 21, 2024 · 2 comments

Comments

@Kryptonh
Copy link

Kryptonh commented Aug 21, 2024

Versions

  • Python : 3.10.10
  • MacOS version : 14.5
  • XCode Version : 15.4
  • Cython version : 3.0.0

Describe the bug

I'm trying to use pillow in my project and I get the following error: ImportError: dynamic module does not define module export function (PyInit__imaging)

(I understand that this issue has been closed, but I have new xcode)

To Reproduce

git clone https://github.com/kivy/kivy-ios.git
cd kivy-ios/
python3 -m venv venv
. venv/bin/activate
pip install -e .
python3.10 toolchain.py build kivy python3
python3.10 toolchain.py pip3 install pillow

Expected behavior

Trying to import Pillow in my project

Logs

File "/Users/kryptonh/kivy-ios/checkxcode-ios/YourApp/main.py", line 9, in <module>
   File "/private/var/containers/Bundle/Application/A526DF69-4967-4216-B81B-0368EF9B5044/checkxcode.app/lib/python3.11/site-packages/PIL/Image.py", line 114, in <module>
     from . import _imaging as core
   File "<string>", line 49, in load_module
   File "/Users/kryptonh/kivy-ios/dist/root/python3/lib/python3.11/imp.py", line 343, in load_dynamic
 ImportError: dynamic module does not define module export function (PyInit__imaging)

Xcode Logs

Undefined symbols for architecture arm64:
  "_FT_Bitmap_Convert", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Bitmap_Done", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Bitmap_New", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Done_Face", referenced from:
      _font_dealloc in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Done_Glyph", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _font_getsize in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Get_Char_Index", referenced from:
      _text_layout in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _text_layout in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Get_Glyph", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _font_getsize in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Get_Kerning", referenced from:
      _text_layout in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Glyph_Get_CBox", referenced from:
      _font_getsize in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Glyph_Stroke", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Glyph_To_Bitmap", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Init_FreeType", referenced from:
      _PyInit__imagingft in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Library_Version", referenced from:
      _PyInit__imagingft in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Load_Glyph", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _font_getsize in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _text_layout in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _text_layout in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_New_Face", referenced from:
      _getfont in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_New_Memory_Face", referenced from:
      _getfont in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Select_Charmap", referenced from:
      _getfont in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Set_Pixel_Sizes", referenced from:
      _getfont in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Stroker_Done", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Stroker_New", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_FT_Stroker_Set", referenced from:
      _font_render in libpillow.a[arm64][6](_imagingft.cpython-311-darwin.so.o)
  "_jpeg_CreateCompress", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_CreateDecompress", referenced from:
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_add_quant_table", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_destroy_compress", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_destroy_decompress", referenced from:
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegDecodeCleanup in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_finish_compress", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_finish_decompress", referenced from:
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_read_header", referenced from:
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_read_scanlines", referenced from:
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_resync_to_restart", referenced from:
      _jpeg_buffer_src in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_set_defaults", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_set_quality", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_simple_progression", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_start_compress", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_start_decompress", referenced from:
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_std_error", referenced from:
      _ImagingJpegDecode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_suppress_tables", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_write_marker", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
  "_jpeg_write_scanlines", referenced from:
      _ImagingJpegEncode in libpillow.a[arm64][2](_imaging.cpython-311-darwin.so.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Screenshots

Additional context

I noticed that I don't have libpillow.a in General -> Frameworks, Libraries and Embedded Content (not available for some reason)

Moreover, when I do an update to python3.10 toolchain.py [project_path], I get a series of errors:

Undefined symbol: _FT_Bitmap_Convert

Undefined symbol: _FT_Bitmap_Done

Undefined symbol: _FT_Bitmap_New

Undefined symbol: _FT_Done_Face

Undefined symbol: _FT_Done_Glyph

Undefined symbol: _FT_Get_Char_Index

Undefined symbol: _FT_Get_Glyph

Undefined symbol: _FT_Get_Kerning

Undefined symbol: _FT_Glyph_Get_CBox

Undefined symbol: _FT_Glyph_Stroke

Undefined symbol: _FT_Glyph_To_Bitmap

Undefined symbol: _FT_Init_FreeType

Undefined symbol: _FT_Library_Version

Undefined symbol: _FT_Load_Glyph

Undefined symbol: _FT_New_Face

Undefined symbol: _FT_New_Memory_Face

Undefined symbol: _FT_Select_Charmap

Undefined symbol: _FT_Set_Pixel_Sizes

Undefined symbol: _FT_Stroker_Done

Undefined symbol: _FT_Stroker_New

Undefined symbol: _FT_Stroker_Set

Undefined symbol: _jpeg_CreateCompress

Undefined symbol: _jpeg_CreateDecompress

Undefined symbol: _jpeg_add_quant_table

Undefined symbol: _jpeg_destroy_compress

Undefined symbol: _jpeg_destroy_decompress

Undefined symbol: _jpeg_finish_compress

Undefined symbol: _jpeg_finish_decompress

Undefined symbol: _jpeg_read_header

Undefined symbol: _jpeg_read_scanlines

Undefined symbol: _jpeg_resync_to_restart

Undefined symbol: _jpeg_set_defaults

Undefined symbol: _jpeg_set_quality

Undefined symbol: _jpeg_simple_progression

Undefined symbol: _jpeg_start_compress

Undefined symbol: _jpeg_start_decompress

Undefined symbol: _jpeg_std_error

Undefined symbol: _jpeg_suppress_tables

Undefined symbol: _jpeg_write_marker

Undefined symbol: _jpeg_write_scanlines

Linker command failed with exit code 1 (use -v to see invocation)

/Users/kryptonh/kivy-ios/checkxcode-ios/main.m
/Users/kryptonh/kivy-ios/checkxcode-ios/main.m:67:5 'PySys_SetArgv' is deprecated

/Users/kryptonh/kivy-ios/checkxcode-ios/main.m:70:5 'PyEval_InitThreads' is deprecated
@Kryptonh
Copy link
Author

Kryptonh commented Aug 22, 2024

I removed libpillow.xcframework from Link binary with libraries in Build Phases in Xcode, the project starts normally, but I get the expected error: ModuleNotFoundError: No module named 'PIL', I guess the problem is in libpillow

@Kryptonh
Copy link
Author

Okay, after long researching I removed 2/5 files with error from libpillow.a and fixed error with importing Pillow framework in Xcode,
but I still get the error:

Traceback (most recent call last):
   File "<string>", line 45, in load_module
   File "/Users/kryptonh/kivy-ios/dist/root/python3/lib/python3.11/imp.py", line 343, in load_dynamic
   File "<frozen importlib._bootstrap>", line 721, in _load
   File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
   File "<frozen importlib._bootstrap>", line 573, in module_from_spec
   File "<frozen importlib._bootstrap_external>", line 1233, in create_module
   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
 ImportError: dynamic module does not define module export function (PyInit_PIL__imaging)
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "/Users/kryptonh/kivy-ios/wbstr-ios/YourApp/main.py", line 79, in <module>
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/kivy/app.py", line 956, in run
     runTouchApp()
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/kivy/base.py", line 574, in runTouchApp
     EventLoop.mainloop()
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/kivy/base.py", line 339, in mainloop
     self.idle()
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/kivy/base.py", line 379, in idle
     Clock.tick()
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/kivy/clock.py", line 733, in tick
     self.post_idle(ts, self.idle())
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/kivy/clock.py", line 776, in post_idle
     self._process_events()
   File "kivy/_clock.pyx", line 620, in kivy._clock.CyClockBase._process_events
   File "kivy/_clock.pyx", line 653, in kivy._clock.CyClockBase._process_events
   File "kivy/_clock.pyx", line 649, in kivy._clock.CyClockBase._process_events
   File "kivy/_clock.pyx", line 218, in kivy._clock.ClockEvent.tick
   File "/Users/kryptonh/kivy-ios/wbstr-ios/YourApp/main.py", line 63, in updt
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/imageio/v2.py", line 396, in imwrite
     with imopen(uri, "wi", **imopen_args) as file:
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/imageio/core/imopen.py", line 196, in imopen
     plugin_instance = candidate_plugin(request, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/imageio/config/plugins.py", line 107, in partial_legacy_plugin
     return LegacyPlugin(request, legacy_plugin)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/imageio/core/legacy_plugin_wrapper.py", line 85, in __init__
     if not self._format.can_write(request):
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/imageio/core/format.py", line 249, in can_write
     return self._can_write(request)
            ^^^^^^^^^^^^^^^^^^^^^^^^
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/imageio/plugins/pillow_legacy.py", line 269, in _can_write
     Image = self._init_pillow()
             ^^^^^^^^^^^^^^^^^^^
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/imageio/plugins/pillow_legacy.py", line 247, in _init_pillow
     from PIL import Image
   File "/private/var/containers/Bundle/Application/C41062EE-7FC2-4C5C-8BBF-58602A29653A/wbstr.app/lib/python3.11/site-packages/PIL/Image.py", line 109, in <module>
     from . import _imaging as core
   File "<string>", line 49, in load_module
   File "/Users/kryptonh/kivy-ios/dist/root/python3/lib/python3.11/imp.py", line 343, in load_dynamic
 ImportError: dynamic module does not define module export function (PyInit__imaging)

Maybe Pillow 8.2.0 (standard recipe version for kivy-ios) too old for Xcode 15....?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant