PythonKit Crashing Swift Project

267 views Asked by At

I'm building an ios app using Xcode (11.6) and Swift (5.1.3). The backend of my app relies on a Python library so I'm integrating a python script into my project using the PythonKit library (I'll leave a link to the github below). I added the package dependency and am able to run my app with the import statement at the top, but as soon as I make a call to my function that uses the library my app crashes and is unable to run. Here's my function that uses the library

import PythonKit


func test() -> String {
    let sys = Python.import("sys")
    sys.path.append("/Users/name/") // path to your Python file's directory.
    let example = Python.import("pythonScript") // import your Python file.
    let res = example.getData() // call your Python function.
    return (String(res) ?? "Empty") //returns "Empty" if res is nil
}

getData() is the function in my python script

Since the app is able to run perfectly fine with the import statement at the top and only crashes when I make a call to test(), would this mean that the package is linked/compiled fine and that the issue is with the library itself? Or is that not necessarily true? Regardless, what are some potential causes for the app to be crashing?

github link: https://github.com/pvieito/PythonKit.git

0

There are 0 answers