結論
- 今のところ、ピュアなPythonは組み込んで使えそう
- 3rd partyのライブラリを含める方法は分からずじまい
参考
- Embedding a Python interpreter inside a MacOS / iOS app, and publishing to the App Store successfully.
- 一番まとまっている
python-stdlib
などをXcodeにコピーするときはFolder Referenceにチェックする- またビルドスクリプトはそのままだと動かないので、記事のコメントを参照
- この記事のコメントに3rdライブラリを組み込んだ紹介があったが、手元ではうまく動かず…。
- PythonSample
- Embedding Python in a Swift App Using Xcode (Apple Silicon and Intel)
- こちらが手順がより詳しい
set -e echo "Signing contents of $CODESIGNING_FOLDER_PATH/Contents/Resources/python-stdlib/lib-dynload as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SIGN_IDENTITY)" cd "$CODESIGNING_FOLDER_PATH/Contents/Resources/python-stdlib/lib-dynload" /usr/bin/codesign --force --sign "$EXPANDED_CODE_SIGN_IDENTITY" --options runtime --timestamp=none --preserve-metadata=identifier,entitlements,flags --generate-entitlement-der *.so
Could you elaborate on how you managed to integrate a 3rd party library?
Sure. In my case I wanted to add librosa library, and basically I added a script that will download it dependencies to a folder i have control over
python3 -m pip install --target="${CODESIGNING_FOLDER_PATH}/Contents/Resources/" librosa
then, in my Python setup I added this path to my PYTHONPATH let resources = bundle.bundlePath.appending("/Contents/Resources/") setenv("PYTHONPATH", "(stdLibPath):(libDynloadPath):(resources)", 1) I have an example on github https://github.com/brenovaladao/PythonSample
- How to embed a Python interpreter in an iOS app - presented by Łukasz Langa
- 記事と同じような内容のはず。3rd partyまでは言及なし
- From Swift Import Python
- まだ見れていない