我正在尝试在我的 Swift 项目中使用 PythonKit 来使用一些 Python 代码。为此,我下载了新的 Xcode 11 以将 PythonKit 添加为 Swift 包。添加带有 Swift Package 的 PythonKit 后,我在这里就有了这些项目依赖项。

我想在应用程序启动时使用 Python 代码,因此我将对 Python 代码的调用放在我的应用程序委托中的应用程序函数中。
import UIKit
import PythonKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let sys = Python.import("sys")
print("Python Version: \(sys.version)")
sys.path.append("/Users/me/Documents/MyProject/MyPackage/my_python_main_file")
let pythonAPI = Python.import("my_python_main_file")
pythonAPI.main_function.call()
return true
}
Run Code Online (Sandbox Code Playgroud)
运行我的项目后,出现以下错误:
致命错误:找不到 Python 库。使用 Python 库的路径设置 PYTHON_LIBRARY 环境变量。 …