KivyMD Xcode 构建错误 - ImportError: 动态模块未定义模块导出函数 (PyInit__imaging)

Posted

技术标签:

【中文标题】KivyMD Xcode 构建错误 - ImportError: 动态模块未定义模块导出函数 (PyInit__imaging)【英文标题】:KivyMD Xcode build error - ImportError: dynamic module does not define module export function (PyInit__imaging) 【发布时间】:2021-12-17 19:40:11 【问题描述】:

我正在使用 MAC Xcode 构建 Python KivyMD 应用程序,代码能够运行,但应用程序没有加载到 iphonesimulator 上。日志如下。

MAC - 大苏尔 Xcode - 13.1 Python - 3.8

2021-11-03 21:36:12.329967+1100 vocgo[9686:99184] Available orientation: KIVY_ORIENTATION=LandscapeLeft LandscapeRight Portrait PortraitUpsideDown
2021-11-03 21:36:12.330145+1100 vocgo[9686:99184] Initializing python
2021-11-03 21:36:12.495467+1100 vocgo[9686:99184] Running main.py: /Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/YourApp/main.pyc
[INFO   ] [Kivy        ] v2.1.0.dev0
[INFO   ] [Kivy        ] Installed at "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.2 (default, Nov  1 2021, 20:29:50) 
[Clang 13.0.0 (clang-1300.0.29.3)]
[INFO   ] [Python      ] Interpreter at "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/vocgo"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_imageio, img_tex (img_dds, img_sdl2, img_ffpyplayer, img_pil ignored)
[INFO   ] [KivyMD      ] 0.104.2, git-bc7d1f5, 2021-06-06 (installed at "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/kivymd/__init__.py")
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
2021-11-03 21:36:13.107136+1100 vocgo[9686:99184] Writing analzed variants.
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'OpenGL ES 2.0 APPLE-19.0.17'>
[INFO   ] [GL          ] OpenGL vendor <b'Apple Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'Apple Software Renderer'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Shading version <b'OpenGL ES GLSL ES 1.00'>
[INFO   ] [GL          ] Texture max size <4096>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
Got dlopen error on Foundation: dlopen(/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation, 0x0001): tried: '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/vocgo-fywrtcoideyfwrepueohqjxjodsj/Build/Products/Debug-iphonesimulator/Foundation.framework/Versions/Current/Foundation' (no such file), '/Users/xxxxxxxx/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/ios.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/vocgo-fywrtcoideyfwrepueohqjxjodsj/Build/Products/Debug-iphonesimulator/Foundation.framework/Versions/C/Foundation' (no such file), '/Users/xxxxxxxx/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation' (no such file), '/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation' (no such file)
Got fallback dlopen error on Foundation: dlopen(/Groups/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation, 0x0001): tried: '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/vocgo-fywrtcoideyfwrepueohqjxjodsj/Build/Products/Debug-iphonesimulator/Foundation.framework/Versions/Current/Foundation' (no such file), '/Users/xxxxxxxx/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Groups/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/Groups/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file)
 Traceback (most recent call last):
   File "/Users/xxxxxxxx/vocgo-ios/YourApp/main.py", line 7, in <module>
   File "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/kivymd/uix/__init__.py", line 8, in <module>
     from kivymd.uix.behaviors import SpecificBackgroundColorBehavior
   File "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/kivymd/uix/behaviors/__init__.py", line 10, in <module>
     from .backgroundcolor_behavior import (
   File "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/kivymd/uix/behaviors/backgroundcolor_behavior.py", line 25, in <module>
     from .elevation import CommonElevationBehavior
   File "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/kivymd/uix/behaviors/elevation.py", line 364, in <module>
     from PIL import Image, ImageDraw, ImageFilter
   File "<frozen zipimport>", line 259, in load_module
   File "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/Pillow-6.1.0-py3.8-macosx-11.6-x86_64.egg/PIL/Image.py", line 95, in <module>
   File "<frozen zipimport>", line 259, in load_module
   File "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/Pillow-6.1.0-py3.8-macosx-11.6-x86_64.egg/PIL/_imaging.py", line 7, in <module>
   File "/Users/xxxxxxxx/Library/Developer/CoreSimulator/Devices/5430FAEF-F9A3-46F7-B9D3-602717473C51/data/Containers/Bundle/Application/9CCC1550-5D8A-4DF7-8186-C052833273B0/vocgo.app/lib/python3.8/site-packages/Pillow-6.1.0-py3.8-macosx-11.6-x86_64.egg/PIL/_imaging.py", line 6, in __bootstrap__
   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 vocgo[9686:99184] Application quit abnormally!

我听说 KivyMD 在使用 Xcode 构建时仍然存在许多问题。我无法找到有关此错误的有价值的答案。我觉得我有不止一个问题。请阐明一些观点。非常感谢。

【问题讨论】:

我刚刚尝试在我的 iPad 上构建和运行一个非 KivyMD 应用程序——一个我已经使用了一年或更长时间的应用程序——并且遇到了类似的错误。所以它可能不仅仅是 KivyMD 应用程序。也使用 Big Sur Xcode 13.1 但 python 3.7 嗯,我的是 Python 3.8。你的有同样的成像 pyinit 错误吗? ImportError:动态模块没有定义模块导出函数(PyInit__imaging) 【参考方案1】:

我设法克服了这个问题。我不确切知道哪个操作可以直接解决问题。但我将在下面列出它们。

一、构建kivy-ioshttps://github.com/kivy/kivy-ios时,使用下面的,不要使用pip3 install kivy-ios。

git clone https://github.com/kivy/kivy-ios.git
cd kivy-ios/
python3 -m venv venv
. venv/bin/activate
pip install -e .

二,在你的 app 文件夹中创建 kivy-ios 文件夹后,激活你的虚拟环境并在 kivy-ios 目录中安装 cython,其中包括构建你的 kivy、python3、openssl 和其他配方。

三、创建你的Xcode项目时,运行

toolchain create <title> <app_directory>

在 kivy-ios 目录下也是如此。

四、我这次用的是Python3.9。

最后,您的目录应如下所示。我还建议使用工具链构建所有基本配方。

【讨论】:

这是一个很好的 youtube 剪辑。感谢作者 PeanutTheAdmin。 youtube.com/watch?v=6gLGyrlgqCU. Github Kivy-ios 确认了原因。诀窍是使用 - git clone github.com/kivy/kivy-ios.git ------------ github.com/kivy/kivy-ios/issues/644

以上是关于KivyMD Xcode 构建错误 - ImportError: 动态模块未定义模块导出函数 (PyInit__imaging)的主要内容,如果未能解决你的问题,请参考以下文章

使用 KivyMD 库运行应用程序时出现错误 No module named 'kivymd.app'

KivyMD 错误:ValueError:KivyMD:App 对象必须在加载根小部件之前进行初始化

打包 kivymd 应用程序时发生错误

使用 KivyMD 和 Pyinstaller 导入错误

Ubuntu 18.04 上的 KivyMD 安装错误

如何修复 Kivymd MDDataTable python3 的“内联错误”