forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitializePython.swift
More file actions
25 lines (21 loc) · 901 Bytes
/
InitializePython.swift
File metadata and controls
25 lines (21 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Foundation
import Python
import PythonKit
@available( *, deprecated, message: "Testing" )
func initializePython() {
guard let sitePackagePath = Bundle.main.path(forResource: "site-packages", ofType: nil),
let stdLibPath = Bundle.main.path(forResource: "python-stdlib", ofType: nil),
let libDynloadPath = Bundle.main.path(
forResource: "python-stdlib/lib-dynload",
ofType: nil
) else { return }
setenv("PYTHONHOME", stdLibPath, 1)
setenv("PYTHONPATH", "\(stdLibPath):\(libDynloadPath):\(sitePackagePath)", 1)
Py_Initialize()
let sys = Python.import("sys")
print("Python Version: \(sys.version_info.major).\(sys.version_info.minor)")
print("Python Encoding: \(sys.getdefaultencoding().upper())")
print("Python Path: \(sys.path)")
let llms = Python.import("langchain.llms")
print(llms.OpenAI)
}