About my iOS_project:I used PythonKit and Python Apple support
And done:
set PythonPath:
guard let stdLibPath = Bundle.main.path(forResource: "python-stdlib", ofType: nil) else { return }
guard let stdDynloadPath = Bundle.main.path(forResource: "python-stdlib/lib-dynload", ofType: nil) else { return }
setenv("PYTHONHOME", stdLibPath, 1)
setenv("PYTHONPATH", "(stdLibPath):(stdDynloadPath)", 1)
Py_Initialize()
And made other configurations,include add Sign Python Binary Modules to Xcode: like the USAGE on Python Apple support。
It can work on debug run to my iPhone, I can call the methods in my custom Python file。
But can't work on release or TestFlight。
On release,It will not crash when code execution to set pythonPath and Py_Initialize(),But When I call Python methods,it crash on : PythonKit- PythonInterface- init-builtins = PythonObject(PyEval_GetBuiltins())
perhaps on PythonLibrary+Symbols:
Py_IncRef(pointer)*
Looks like a null pointer error,Because I saw a lot of 0x0000000000000000 in Xcode
example:sharedMethodDefinition UnsafeMutablePointer<PythonKit.PyMethodDef> 0x0000000000000000
Now I hope someone can help me fix it,It has been bothering me for two months now
But now it make a new question,
when I distribute on app store connect,show error:
Asset validation failed
Invalid bundle structure. The “xxxxxx.app/python-stdlib/lib-dynload/math.cpython-39-iphoneos.so” binary file is not permitted. Your app cannot contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles. For details, visit: https://developer.apple.com/documentation/bundleresources/placing_content_in_a_bundle (ID: 74345377-b2bb-466b-bc4d-e3edb8a8f429)
Including all the files:
All the .io in python-stdlib/lib-dynload,and python-stdlib/config-3.10-iphoneos, python-stdlib/config-3.10-iphonesimulator.arm64 , python-stdlib/config-3.10-iphonesimulator.x86_64
IMO this issue is not related to Swift language itself.
It is recommended that you post the issue to the Apple Developer Forum or the Issue area of PythonKit repo.
It is recommended that you post [to] the Issue area of PythonKit repo.
Agreed. I can explain what iOS is complaining about here, but for advice on how to fix it you’ll need to talk to someone with experience using PythonKit on iOS.
A .so file is typically some sort of Mach-O image, either MH_DYLIB or MH_BUNDLE depending on how it was built. iOS and its child platforms do not allow standalone Mach-O images. While you can break your app up into components, each component must be a framework placed in the MyApp.app/Frameworks directory. See Placing Content in a Bundle for the rules.
To get this to work you’ll either have to:
Statically link that code into your app or an existing framework, and then tweak the code that loads it, or
Wrap the .so into a framework, place it in MyApp.app/Frameworks, and then tweak the code that loads it.
How you’d do this is very specific to Python, hence my initial advice.