@@ -194,13 +194,21 @@ To add Python to an iOS Xcode project:
194194 adjusting paths as needed. Ensure that this folder is associated with your
195195 app target.
196196
197- 4. Select the app target by selecting the root node of your Xcode project, then
197+ 4. Create folders to store your third-party dependencies (e.g., packages you've
198+ installed from PyPI). You'll need a separate dependencies folder for iOS
199+ devices and iOS simulators. In the following instructions, we'll assume
200+ you've used folders named ``app_packages.iphoneos `` and
201+ ``app_packages.iphonesimulator ``, located in the root of your project; you
202+ can use any other location by adjusting paths as needed. These folders
203+ *should not * be associated with the app target.
204+
205+ 5. Select the app target by selecting the root node of your Xcode project, then
198206 the target name in the sidebar that appears.
199207
200- 5 . In the "General" settings, under "Frameworks, Libraries and Embedded
208+ 6 . In the "General" settings, under "Frameworks, Libraries and Embedded
201209 Content", add ``Python.xcframework ``, with "Embed & Sign" selected.
202210
203- 6 . In the "Build Settings" tab, modify the following:
211+ 7 . In the "Build Settings" tab, modify the following:
204212
205213 - Build Options
206214
@@ -216,7 +224,7 @@ To add Python to an iOS Xcode project:
216224
217225 * Quoted Include In Framework Header: No
218226
219- 7 . Add a build step that processes the Python standard library, and your own
227+ 8 . Add a build step that processes the Python standard library, and your own
220228 Python binary dependencies. In the "Build Phases" tab, add a new "Run
221229 Script" build step *before * the "Embed Frameworks" step, but *after * the
222230 "Copy Bundle Resources" step. Name the step "Process Python libraries",
@@ -228,11 +236,18 @@ To add Python to an iOS Xcode project:
228236 set -e
229237 source " $PROJECT_DIR /Python.xcframework/build/utils.sh"
230238 install_python Python.xcframework app
239+ if [ " $EFFECTIVE_PLATFORM_NAME " = " -iphonesimulator" ]; then
240+ APP_PACKAGES_DIR=" $PROJECT_DIR /app_packages.iphonesimulator/"
241+ else
242+ APP_PACKAGES_DIR=" $PROJECT_DIR /app_packages.iphoneos/"
243+ fi
244+ rsync -au --delete " $APP_PACKAGES_DIR " " $CODESIGNING_FOLDER_PATH /app_packages"
245+ install_site_packages Python.xcframework app_packages
231246
232247 If you have placed your XCframework somewhere other than the root of your
233248 project, modify the path to the first argument.
234249
235- 8 . Add Objective C code to initialize and use a Python interpreter in embedded
250+ 9 . Add Objective C code to initialize and use a Python interpreter in embedded
236251 mode. You should ensure that:
237252
238253 * UTF-8 mode (:c:member: `PyPreConfig.utf8_mode `) is *enabled *;
@@ -241,36 +256,14 @@ To add Python to an iOS Xcode project:
241256 * Signal handlers (:c:member: `PyConfig.install_signal_handlers `) are *enabled *;
242257 * System logging (:c:member: `PyConfig.use_system_logger `) is *enabled *
243258 (optional, but strongly recommended; this is enabled by default);
244- * :envvar: `PYTHONHOME ` for the interpreter is configured to point at the
245- ``python `` subfolder of your app's bundle; and
246- * The :envvar: `PYTHONPATH ` for the interpreter includes:
247-
248- - the ``python/lib/python3.X `` subfolder of your app's bundle,
249- - the ``python/lib/python3.X/lib-dynload `` subfolder of your app's bundle, and
250- - the ``app `` subfolder of your app's bundle
259+ * The interpreter's home direectory (:c:member: `PyConfig.home `) is configured
260+ to point at the ``python `` subfolder of your app's bundle; and
261+ * The interpreter's module search paths (:c:member: `PyConfig.home `) includes
262+ the ``app `` subfolder of your app's bundle.
251263
252264 Your app's bundle location can be determined using ``[[NSBundle mainBundle]
253265 resourcePath] ``.
254266
255- Steps 7 and 8 of these instructions assume that you have a single folder of
256- pure Python application code, named ``app ``. If you have third-party binary
257- modules in your app, some additional steps will be required:
258-
259- * You need to ensure that any folders containing third-party binaries are
260- either associated with the app target, or are explicitly copied as part of
261- step 7. Step 7 should also purge any binaries that are not appropriate for
262- the platform a specific build is targeting (i.e., delete any device binaries
263- if you're building an app targeting the simulator).
264-
265- * If you're using a separate folder for third-party packages, ensure that
266- folder is added to the end of the call to ``install_python `` in step 7, and
267- as part of the :envvar: `PYTHONPATH ` configuration in step 8.
268-
269- * If any of the folders that contain third-party packages will contain ``.pth ``
270- files, you should add that folder as a *site directory * (using
271- :meth: `site.addsitedir `), rather than adding to :envvar: `PYTHONPATH ` or
272- :attr: `sys.path ` directly.
273-
274267Testing a Python package
275268------------------------
276269
0 commit comments