@@ -187,13 +187,21 @@ To add Python to an iOS Xcode project:
187187 adjusting paths as needed. Ensure that this folder is associated with your
188188 app target.
189189
190- 4. Select the app target by selecting the root node of your Xcode project, then
190+ 4. Create folders to store your third-party dependencies (e.g., packages you've
191+ installed from PyPI). You'll need a separate dependencies folder for iOS
192+ devices and iOS simulators. In the following instructions, we'll assume
193+ you've used folders named ``app_packages.iphoneos `` and
194+ ``app_packages.iphonesimulator ``, located in the root of your project; you
195+ can use any other location by adjusting paths as needed. These folders
196+ *should not * be associated with the app target.
197+
198+ 5. Select the app target by selecting the root node of your Xcode project, then
191199 the target name in the sidebar that appears.
192200
193- 5 . In the "General" settings, under "Frameworks, Libraries and Embedded
201+ 6 . In the "General" settings, under "Frameworks, Libraries and Embedded
194202 Content", add ``Python.xcframework ``, with "Embed & Sign" selected.
195203
196- 6 . In the "Build Settings" tab, modify the following:
204+ 7 . In the "Build Settings" tab, modify the following:
197205
198206 - Build Options
199207
@@ -209,7 +217,7 @@ To add Python to an iOS Xcode project:
209217
210218 * Quoted Include In Framework Header: No
211219
212- 7 . Add a build step that processes the Python standard library, and your own
220+ 8 . Add a build step that processes the Python standard library, and your own
213221 Python binary dependencies. In the "Build Phases" tab, add a new "Run
214222 Script" build step *before * the "Embed Frameworks" step, but *after * the
215223 "Copy Bundle Resources" step. Name the step "Process Python libraries",
@@ -221,11 +229,18 @@ To add Python to an iOS Xcode project:
221229 set -e
222230 source " $PROJECT_DIR /Python.xcframework/build/utils.sh"
223231 install_python Python.xcframework app
232+ if [ " $EFFECTIVE_PLATFORM_NAME " = " -iphonesimulator" ]; then
233+ APP_PACKAGES_DIR=" $PROJECT_DIR /app_packages.iphonesimulator/"
234+ else
235+ APP_PACKAGES_DIR=" $PROJECT_DIR /app_packages.iphoneos/"
236+ fi
237+ rsync -au --delete " $APP_PACKAGES_DIR " " $CODESIGNING_FOLDER_PATH /app_packages"
238+ install_site_packages Python.xcframework app_packages
224239
225240 If you have placed your XCframework somewhere other than the root of your
226241 project, modify the path to the first argument.
227242
228- 8 . Add Objective C code to initialize and use a Python interpreter in embedded
243+ 9 . Add Objective C code to initialize and use a Python interpreter in embedded
229244 mode. You should ensure that:
230245
231246 * UTF-8 mode (:c:member: `PyPreConfig.utf8_mode `) is *enabled *;
@@ -234,36 +249,14 @@ To add Python to an iOS Xcode project:
234249 * Signal handlers (:c:member: `PyConfig.install_signal_handlers `) are *enabled *;
235250 * System logging (:c:member: `PyConfig.use_system_logger `) is *enabled *
236251 (optional, but strongly recommended; this is enabled by default);
237- * :envvar: `PYTHONHOME ` for the interpreter is configured to point at the
238- ``python `` subfolder of your app's bundle; and
239- * The :envvar: `PYTHONPATH ` for the interpreter includes:
240-
241- - the ``python/lib/python3.X `` subfolder of your app's bundle,
242- - the ``python/lib/python3.X/lib-dynload `` subfolder of your app's bundle, and
243- - the ``app `` subfolder of your app's bundle
252+ * The interpreter's home direectory (:c:member: `PyConfig.home `) is configured
253+ to point at the ``python `` subfolder of your app's bundle; and
254+ * The interpreter's module search paths (:c:member: `PyConfig.home `) includes
255+ the ``app `` subfolder of your app's bundle.
244256
245257 Your app's bundle location can be determined using ``[[NSBundle mainBundle]
246258 resourcePath] ``.
247259
248- Steps 7 and 8 of these instructions assume that you have a single folder of
249- pure Python application code, named ``app ``. If you have third-party binary
250- modules in your app, some additional steps will be required:
251-
252- * You need to ensure that any folders containing third-party binaries are
253- either associated with the app target, or are explicitly copied as part of
254- step 7. Step 7 should also purge any binaries that are not appropriate for
255- the platform a specific build is targeting (i.e., delete any device binaries
256- if you're building an app targeting the simulator).
257-
258- * If you're using a separate folder for third-party packages, ensure that
259- folder is added to the end of the call to ``install_python `` in step 7, and
260- as part of the :envvar: `PYTHONPATH ` configuration in step 8.
261-
262- * If any of the folders that contain third-party packages will contain ``.pth ``
263- files, you should add that folder as a *site directory * (using
264- :meth: `site.addsitedir `), rather than adding to :envvar: `PYTHONPATH ` or
265- :attr: `sys.path ` directly.
266-
267260Testing a Python package
268261------------------------
269262
0 commit comments