【发布时间】:2022-10-05 00:47:39
【问题描述】:
我在用着PythonKit在我的 MacOS Swift 项目中。目前我正在使用 Python 2.7,但从 MacOs 12.3 开始不再支持它,所以我正在尝试迁移到 Python 3,但它不起作用。
func applicationDidFinishLaunching(_ notification: Notification) {
if #available(OSX 12, *) {
PythonLibrary.useVersion(3)
}
else {
PythonLibrary.useVersion(2)
}
let sys = Python.import("sys")
print("Python \(sys.version_info.major).\(sys.version_info.minor)")
print("Python Version: \(sys.version)")
print("Python Encoding: \(sys.getdefaultencoding().upper())")
sys.path.append(Bundle.main.resourceURL!.absoluteURL.path)
let checker = Python.import("checkLibrary")
_ = Array(checker.check())
}
这是错误消息:
PythonKit/PythonLibrary.swift:46: Fatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.
该代码在第 9 行 (let sys = Python.import("sys")) 上的 MacOs 12 上失败,因此我无法以任何方式进行交互。
我已经尝试禁用沙盒和强化运行时,但似乎没用。
【问题讨论】: