kivy-ios
kivy-ios copied to clipboard
ImportError: dynamic module does not define module export function (PyInit__imaging)
Error: ImportError: dynamic module does not define module export function (PyInit__imaging)
- Python : 3.9
- MacOS version : Big Sur
- XCode Version : 13.0
- Cython version : 0.29.24
ISSUE/BACKGROUND: I am fairly new to python and attempting to create my first mobile app using KivyMD for iOS. I am able to get the application onto my iPhone but it crashes with the below error. It also fails on a Simulator as well with the exact same error. I have followed all the steps outlined in kivy-ios ReadMe. For reference I have placed my terminal commands below.
I found this same error in the following post but it wasn't clearly answered as to what causes this error. I also read several StackOverFlow posts and it appears to be a python2 vs python3 related error (Init being updated to PyInit with deprecation of PIL....or I could be wrong. Please correct me as I am still new to all this) but I am using a virtual environment and made sure only python 3 is installed. Can someone please help in advising what is causing this issue and how to go about fixing it?
ERROR: Error: ImportError: dynamic module does not define module export function (PyInit__imaging)
TERMINAL COMMANDS:
brew install autoconf automake libtool pkg-config
brew link libtool
cd into local app directory ()
git clone https://github.com/kivy/kivy-ios.git
cd kivy-ios/
python3 -m venv venv
. venv/bin/activate
pip install -e .
pip install cython
python3 toolchain.py build kivy python3
python3 toolchain.py create
Xcode Build Logs
2021-09-26 18:52:40.097319-0400 bebo[77985:4400838] Available orientation: KIVY_ORIENTATION=LandscapeLeft LandscapeRight Portrait PortraitUpsideDown
2021-09-26 18:52:40.097557-0400 bebo[77985:4400838] Initializing python
2021-09-26 18:52:40.530238-0400 bebo[77985:4400838] Running main.py: /Users/MikesMac/Library/Developer/CoreSimulator/Devices/91883F97-902C-41D8-BCA5-6F7CA24EEB27/data/Containers/Bundle/Application/90CB0A60-2777-4F62-A8DA-BB6E3A402CCB/bebo.app/YourApp/main.pyc
[INFO ] [Kivy ] v2.1.0.dev0
[INFO ] [Kivy ] Installed at "/Users/MikesMac/Library/Developer/CoreSimulator/Devices/91883F97-902C-41D8-BCA5-6F7CA24EEB27/data/Containers/Bundle/Application/90CB0A60-2777-4F62-A8DA-BB6E3A402CCB/bebo.app/lib/python3.9/site-packages/kivy/init.py"
[INFO ] [Python ] v3.9.2 (default, Sep 24 2021, 20:14:03)
[Clang 13.0.0 (clang-1300.0.29.3)]
[INFO ] [Python ] Interpreter at "/Users/MikesMac/Library/Developer/CoreSimulator/Devices/91883F97-902C-41D8-BCA5-6F7CA24EEB27/data/Containers/Bundle/Application/90CB0A60-2777-4F62-A8DA-BB6E3A402CCB/bebo.app/bebo"
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [Image ] Providers: img_imageio, img_tex (img_dds, img_sdl2, img_ffpyplayer, img_pil ignored)
[INFO ] [KivyMD ] 1.0.0.dev0 (installed at "/Users/MikesMac/Library/Developer/CoreSimulator/Devices/91883F97-902C-41D8-BCA5-6F7CA24EEB27/data/Containers/Bundle/Application/90CB0A60-2777-4F62-A8DA-BB6E3A402CCB/bebo.app/lib/python3.9/site-packages/kivymd/init.py")
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
2021-09-26 18:52:43.620702-0400 bebo[77985:4400838] Writing analzed variants.
[INFO ] [GL ] Using the "OpenGL ES 2" graphics system
[INFO ] [GL ] Backend used
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/MikesMac/ios-test/kivy-ios/bebo-ios/YourApp/main.py", line 10, in
Screenshots

Additional context Add any other context about the problem here.
i have same error
@faris4017 and @mpeguese, if you install your kivy-ios via pip, uninstall kivy-ios and try to install the latest version from Github using pip install git+https://github.com/kivy/kivy-ios.git after successful installation, build pillow and try it, that should work
Same error too. Advice above didn't change the situation unfortunately.
Same error I had. The same code can be published to Google play without problem. In Xcode I had this PyInit_imaging erorr. Can't make it work, help please!
File "/Users/xxxxxxxx/dist/root/python3/lib/python3.8/imp.py", line 342, in load_dynamic ImportError: dynamic module does not define module export function (PyInit__imaging) 2021-11-03 21:36:14.027017+1100 xxxxx[9686:99184] Application quit abnormally!
Hi all, me again. I managed to overcome the issue. I posted it to stackoverflow. https://stackoverflow.com/questions/69824628/kivymd-xcode-build-error-importerror-dynamic-module-does-not-define-module-ex/70080251#70080251
@Jesscarlett this is due to #606.
The kivy-ios version available on PyPI is 1.2.1, which doesn't include that patch, unlike the current master version which includes it.
I'm closing this issue, cause should be fixed via #606. But feel free to reopen if needed.
This is not working for me. Same error, no solution worked for me.
Please could you reopen the issue?. My recipes shows "pillow 8.2.0" as follows:
[INFO ] Using the bundled version for recipe 'audiostream'
audiostream master
[INFO ] Using the bundled version for recipe 'click'
click 7.1.2
[INFO ] Using the bundled version for recipe 'curly'
curly master
[INFO ] Using the bundled version for recipe 'cymunk'
cymunk master
[INFO ] Using the bundled version for recipe 'ffmpeg'
ffmpeg n4.3.1
[INFO ] Using the bundled version for recipe 'ffpyplayer'
ffpyplayer 4.2.0
[INFO ] Using the bundled version for recipe 'flask'
flask 1.1.2
[INFO ] Using the bundled version for recipe 'freetype'
freetype 2.5.5
[INFO ] Using the bundled version for recipe 'host_setuptools'
[INFO ] Using the bundled version for recipe 'host_setuptools3'
host_setuptools3 59.2.0
[INFO ] Using the bundled version for recipe 'hostopenssl'
hostopenssl 1.1.1l
[INFO ] Using the bundled version for recipe 'hostpython3'
hostpython3 3.9.9
[INFO ] Using the bundled version for recipe 'ios'
ios master
[INFO ] Using the bundled version for recipe 'itsdangerous'
itsdangerous 1.1.0
[INFO ] Using the bundled version for recipe 'jinja2'
jinja2 2.11.2
[INFO ] Using the bundled version for recipe 'kivent_core'
kivent_core master
[INFO ] Using the bundled version for recipe 'kivy'
kivy b5ec51ed2315a9a890f264b0df6d23c8e6341d42
[INFO ] Using the bundled version for recipe 'libcurl'
libcurl 7.65.3
[INFO ] Using the bundled version for recipe 'libffi'
libffi 3.2.1
[INFO ] Using the bundled version for recipe 'libjpeg'
libjpeg v9d
[INFO ] Using the bundled version for recipe 'libpng'
libpng 1.6.26
[INFO ] Using the bundled version for recipe 'libzbar'
libzbar 0.10
[INFO ] Using the bundled version for recipe 'markupsafe'
markupsafe 1.1.1
[INFO ] Using the bundled version for recipe 'netifaces'
netifaces 0.10.9
[INFO ] Using the bundled version for recipe 'numpy'
numpy 1.20.2
[INFO ] Using the bundled version for recipe 'openssl'
openssl 1.1.1l
[INFO ] Using the bundled version for recipe 'photolibrary'
photolibrary master
[INFO ] Using the bundled version for recipe 'pillow'
pillow 8.2.0
[INFO ] Using the bundled version for recipe 'plyer'
plyer master
[INFO ] Using the bundled version for recipe 'pycrypto'
pycrypto 2.6.1
[INFO ] Using the bundled version for recipe 'pykka'
pykka 1.2.1
[INFO ] Using the bundled version for recipe 'pyobjus'
pyobjus master
[INFO ] Using the bundled version for recipe 'python3'
python3 3.9.9
[INFO ] Using the bundled version for recipe 'pyyaml'
pyyaml 3.11
[INFO ] Using the bundled version for recipe 'sdl2'
sdl2 7cc4fc886d9e
[INFO ] Using the bundled version for recipe 'sdl2_image'
sdl2_image 2.0.4
[INFO ] Using the bundled version for recipe 'sdl2_mixer'
sdl2_mixer 2.0.4
[INFO ] Using the bundled version for recipe 'sdl2_ttf'
sdl2_ttf 2.0.15
[INFO ] Using the bundled version for recipe 'werkzeug'
werkzeug 1.0.1
[INFO ] Using the bundled version for recipe 'zbarlight'
zbarlight 1.2
But the error remains:
2021-12-09 13:58:18.929588+0100 mytest[467:13831] Available orientation: KIVY_ORIENTATION=LandscapeLeft LandscapeRight Portrait PortraitUpsideDown
2021-12-09 13:58:18.929752+0100 mytest[467:13831] Initializing python
2021-12-09 13:58:19.093802+0100 mytest[467:13831] Running main.py: /private/var/containers/Bundle/Application/059A117F-2CEF-45F2-9CEF-99E7E7D4E0D6/mytest.app/YourApp/main.pyc
[INFO ] [Kivy ] v2.1.0.dev0
[INFO ] [Kivy ] Installed at "/private/var/containers/Bundle/Application/059A117F-2CEF-45F2-9CEF-99E7E7D4E0D6/mytest.app/lib/python3.9/site-packages/kivy/init.py"
[INFO ] [Python ] v3.9.9 (main, Dec 8 2021, 10:46:27)
[Clang 13.0.0 (clang-1300.0.29.3)]
[INFO ] [Python ] Interpreter at "/private/var/containers/Bundle/Application/059A117F-2CEF-45F2-9CEF-99E7E7D4E0D6/mytest.app/mytest"
[INFO ] [KivyMD ] 0.104.2, git-bc7d1f5, 2021-06-06 (installed at "/private/var/containers/Bundle/Application/059A117F-2CEF-45F2-9CEF-99E7E7D4E0D6/mytest.app/lib/python3.9/site-packages/kivymd/init.py")
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [Image ] Providers: img_imageio, img_tex, img_sdl2 (img_dds, img_ffpyplayer, img_pil ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
2021-12-09 13:58:20.440892+0100 mytest[467:13831] Metal GPU Frame Capture Enabled
2021-12-09 13:58:20.443206+0100 mytest[467:13831] Metal API Validation Enabled
[INFO ] [GL ] Using the "OpenGL ES 2" graphics system
[INFO ] [GL ] Backend used
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jose/Documents/kivy-ios/mytest-ios/YourApp/main.py", line 2, in
HI @jjosecarmona and @K1NGC0D3R ,
I probably already suggested this fix to @K1NGC0D3R on Discord, but I'm not sure about the result.
Has Pillow been built after the code project creation?
If yes, did you updated the project accordingly via toolchain update PATH/TO/YOUR.xcodeproj ?
If toolchain update ... doesn't works, what happens if you manually add libpillow.a to your General->Frameworks, Libraries, and Embedded Content Xcode tab?
When I manually added libpillow.a
Xcode is now crashing after compiling
I fixed the crashing
But now new error
ImportError: The _imaging extension was built for another version of Pillow or PIL: Core version: 8.2.0 Pillow version: 8.4.0 2021-12-10 11:27:05.355568+0530 bmicalc[8063:321372] Application quit abnormally! 2021-12-10 11:27:05.402427+0530 bmicalc[8063:321372] Leaving
I have fixed my error
Thank you
After some investigation on Discord, with a user that had the same issue, we came to a conclusion:
If Pillow (and could happen with other dependencies that actually need a recipe to build) is not built via toolchain build pillow before a dependant (Like kivymd) is installed via toolchain pip install ...., a non-recipe version of the dependency gets incorrectly installed.
That could lead to the issue that has been reported here.
As a workaround, until it get fixed, the following approach should be followed (I'm using as an example the specific kivymd case, but applies to others):
toolchain build python3 kivytoolchain build pillowtoolchain pip install kivymd
I don't use this project, but I searched everywhere and this is one of the most active issues for this error, so I thought I'd comment.
I resolved this error by using python3.9
@misl6 I had the same issue any fixing?
Regards,
good morning all
I have the same issue and I tried all the solution above with no hop can any one provide me the right steps to over come this issue?
MacOs:big sur running on VM
Issue:
ImportError: dynamic module does not define module export function (PyInit__imaging) 2022-02-04 22:06:38.477149-0800 ios-app[26728:720920] Application quit abnormally!
hope to hear from you soon thanks in advance...
After some investigation on Discord, with a user that had the same issue, we came to a conclusion:
If
Pillow(and could happen with other dependencies that actually need a recipe to build) is not built viatoolchain build pillowbefore a dependant (Likekivymd) is installed viatoolchain pip install ...., a non-recipe version of the dependency gets incorrectly installed.That could lead to the issue that has been reported here.
As a workaround, until it get fixed, the following approach should be followed (I'm using as an example the specific
kivymdcase, but applies to others):
toolchain build python3 kivytoolchain build pillowtoolchain pip install kivymd
@saminapoleon Did you tried to follow these instructions? (From a clean dist)
@misl6 hi and many thanx for your response, what did you mean (From a clean dist)? also I tried these
toolchain build python3 kivy
toolchain build pillow
toolchain pip install kivymd
but with no hope.
anything else must done?
Regards,
@misl6 I followed the instructions and now I have this issue any idea?
AttributeError: module 'subprocess' has no attribute 'Popen'
Regards
Are you using "subprocess" in your App? If "yes", see: https://github.com/kivy/kivy-ios#why-does-the-python-multiprocesssubprocess-module-not-work
If you need some help or support, please join our Discord Server
@misl6
no im not using subprocess that is why im hanged out.
about discord I can not send any message I have no permission
Regards,
Just to get a few details out of the way, I'm running the latest kivy-ios pulled from github.
Name: kivy-ios Version: 2023.5.21
I'm having a lot of issues getting Pillow to work. Unlike most, I'm not using kivyMD. I'm using pillow to draw text onto an image. When I compile it with kivy on my m1 macbook pro, everything works great using:
- Python 3.11.4
- Pillow 10.0.0.
With kivy-ios, this is what I've tried:
toolchain build python3 kivy toolchain build pillow
That gives the following error:
407 duplicate symbols for architecture arm64 Linker command failed with exit code 1 (use -v to see invocation)
Now if If I "pip install pillow" instead of using "toolchain build pillow", which will give me pillow 10.0.0 instead of pillow the 8.2 given in toolchain:
File "/Users/username/Desktop/dist/root/python3/lib/python3.10/imp.py", line 343, in load_dynamic ImportError: dynamic module does not define module export function (PyInit__imaging)
Any suggestions? Only other library I need is pymysql which pip installs just fine. It's just Pillow that's creating issues.
I think I might have found something:
toolchain pip uninstall pillow
toolchain clean pillow
toolchain build pillow
This downgraded pillow to the working version.
I have fixed my error
Thank you
How did you fixed it please
This is a support issue with three fixes proposed above.
Closing as there is no work to be done by Kivy developers.