From d785ebaba5526aac8fb7819c7f55868c4f9f37b5 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 4 May 2025 21:48:57 -0500 Subject: [PATCH 1/3] Remove some useless paths --- USAGE.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/USAGE.md b/USAGE.md index 6565dd4..76f0d48 100644 --- a/USAGE.md +++ b/USAGE.md @@ -23,8 +23,8 @@ guides: * [iOS](https://docs.python.org/3/using/ios.html#adding-python-to-an-ios-project) For tvOS, watchOS, and visionOS, you should be able to broadly follow the instructions -in the iOS guide. The testbed projects generated on iOS and visionOS may be used as -rough references as well. +in the iOS guide, changing some platform names in the first script. The testbed projects +generated on iOS and visionOS may be used as rough references as well. ### Using Objective C @@ -45,19 +45,15 @@ As a *bare minimum*, you can do the following: ```objc NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; NSString *pythonHome = [NSString stringWithFormat:@"%@/python", resourcePath, nil]; - NSString *pythonPath = [NSString stringWithFormat:@"%@/lib/python3.13", python_home, nil]; - NSString *libDynloadPath = [NSString stringWithFormat:@"%@/lib/python3.13/lib-dynload", python_home, nil]; NSString *appPath = [NSString stringWithFormat:@"%@/app", resourcePath, nil]; setenv("PYTHONHOME", pythonHome, 1); - setenv("PYTHONPATH", [NSString stringWithFormat:@"%@:%@:%@", pythonpath, libDynloadPath, appPath, nil]); + setenv("PYTHONPATH", [NSString stringWithFormat:@"%@:%@:%@", appPath, nil]); Py_Initialize(); // we now have a Python interpreter ready to be used ``` - References to a specific Python version should reflect the version of - Python you are using. Again - this is the *bare minimum* initialization. In practice, you will likely need to configure other aspects of the Python interpreter using the @@ -81,12 +77,10 @@ code will look something like this: 2. Initialize the Python interpreter: ```swift guard let pythonHome = Bundle.main.path(forResource: "python", ofType: nil) else { return } - guard let pythonPath = Bundle.main.path(forResource: "python/lib/python3.13", ofType: nil) else { return } - guard let libDynloadPath = Bundle.main.path(forResource: "python/lib/python3.13/lib-dynload", ofType: nil) else { return } let appPath = Bundle.main.path(forResource: "app", ofType: nil) setenv("PYTHONHOME", pythonHome, 1) - setenv("PYTHONPATH", [pythonPath, libDynloadPath, appPath].compactMap { $0 }.joined(separator: ":"), 1) + setenv("PYTHONPATH", [appPath].compactMap { $0 }.joined(separator: ":"), 1) Py_Initialize() // we now have a Python interpreter ready to be used ``` From 9606b55a3e32506f437b7d4deea9a44936e2ddb3 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 5 May 2025 18:12:24 -0500 Subject: [PATCH 2/3] Update USAGE.md --- USAGE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 76f0d48..5653f77 100644 --- a/USAGE.md +++ b/USAGE.md @@ -48,7 +48,7 @@ As a *bare minimum*, you can do the following: NSString *appPath = [NSString stringWithFormat:@"%@/app", resourcePath, nil]; setenv("PYTHONHOME", pythonHome, 1); - setenv("PYTHONPATH", [NSString stringWithFormat:@"%@:%@:%@", appPath, nil]); + setenv("PYTHONPATH", appPath, 1); Py_Initialize(); @@ -80,7 +80,7 @@ code will look something like this: let appPath = Bundle.main.path(forResource: "app", ofType: nil) setenv("PYTHONHOME", pythonHome, 1) - setenv("PYTHONPATH", [appPath].compactMap { $0 }.joined(separator: ":"), 1) + setenv("PYTHONPATH", appPath, 1) Py_Initialize() // we now have a Python interpreter ready to be used ``` From ccebc536822b27cb009009a9b007f3a12015eef2 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 5 May 2025 18:43:44 -0500 Subject: [PATCH 3/3] Update USAGE.md --- USAGE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 5653f77..072ae1e 100644 --- a/USAGE.md +++ b/USAGE.md @@ -47,8 +47,8 @@ As a *bare minimum*, you can do the following: NSString *pythonHome = [NSString stringWithFormat:@"%@/python", resourcePath, nil]; NSString *appPath = [NSString stringWithFormat:@"%@/app", resourcePath, nil]; - setenv("PYTHONHOME", pythonHome, 1); - setenv("PYTHONPATH", appPath, 1); + setenv("PYTHONHOME", [pythonHome UTF8String], 1); + setenv("PYTHONPATH", [appPath UTF8String], 1); Py_Initialize();