@@ -20,7 +20,7 @@ what Briefcase is doing). The steps required are documented in the CPython usage
2020guides:
2121
2222* [ macOS] ( https://docs.python.org/3/using/mac.html )
23- * [ iOS] ( https://docs.python.org/3.14 /using/ios.html )
23+ * [ iOS] ( https://docs.python.org/3/using/ios.html#adding-python-to-an-ios-project )
2424
2525For tvOS and watchOS, you should be able to broadly follow the instructions in
2626the iOS guide.
@@ -29,7 +29,7 @@ the iOS guide.
2929
3030There are 2 ways to access the Python runtime in your project code.
3131
32- ### Embedded C API.
32+ ### Embedded C API
3333
3434You can use the [ Python Embedded C
3535API] ( https://docs.python.org/3/extending/embedding.html ) to instantiate a Python
@@ -43,37 +43,31 @@ An alternate approach is to use
4343[ PythonKit] ( https://github.com/pvieito/PythonKit ) . PythonKit is a package that
4444provides a Swift API to running Python code.
4545
46- To use PythonKit in your project:
46+ To use PythonKit in your project, add the Python Apple Support package to your
47+ project as described above; then:
4748
48491 . Add PythonKit to your project using the Swift Package manager. See the
4950 PythonKit documentation for details.
5051
51- 2 . Create a file called ` module.modulemap ` inside
52- ` Python.xcframework/macos-arm64_x86_64/Headers/ ` , containing the following
53- code:
54- ```
55- module Python {
56- umbrella header "Python.h"
57- export *
58- link "Python"
59- }
60- ```
61-
62- 3 . In your Swift code, initialize the Python runtime. This should generally be
52+ 2 . In your Swift code, initialize the Python runtime. This should generally be
6353 done as early as possible in the application's lifecycle, but definitely
64- needs to be done before you invoke Python code:
54+ needs to be done before you invoke Python code. References to a specific
55+ Python version should reflect the version of Python you are using:
6556``` swift
6657import Python
6758
68- guard let stdLibPath = Bundle.main.path (forResource : " python-stdlib" , ofType : nil ) else { return }
69- guard let libDynloadPath = Bundle.main.path (forResource : " python-stdlib/lib-dynload" , ofType : nil ) else { return }
70- setenv (" PYTHONHOME" , stdLibPath, 1 )
71- setenv (" PYTHONPATH" , " \( stdLibPath ) :\( libDynloadPath ) " , 1 )
59+ guard let pythonHome = Bundle.main.path (forResource : " python" , ofType : nil ) else { return }
60+ guard let pythonPath = Bundle.main.path (forResource : " python/lib/python3.13" , ofType : nil ) else { return }
61+ guard let libDynloadPath = Bundle.main.path (forResource : " python/lib/python3.13/lib-dynload" , ofType : nil ) else { return }
62+ let appPath = Bundle.main .path (forResource : " app" , ofType : nil )
63+
64+ setenv (" PYTHONHOME" , pythonHome, 1 )
65+ setenv (" PYTHONPATH" , [pythonPath, libDynloadPath, appPath].compactMap { $0 }.joined (separator : " :" ), 1 )
7266Py_Initialize ()
7367// we now have a Python interpreter ready to be used
7468```
7569
76- 5 . Invoke Python code in your app. For example:
70+ 3 . Invoke Python code in your app. For example:
7771``` swift
7872import PythonKit
7973
0 commit comments