-1

I'm trying to run some python code from Xcode but wasn't sure why it can't find the module. All the tutorial I found only shows importing the simple .py file that contains function only no import on the top. I'm using python3. TIA

import SwiftUI
import PythonKit

struct ContentView: View {
    
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .onAppear() {
            runPython()
        }
        .padding()
    }
    
    func runPython() {
        let sys = Python.import("sys")
        sys.path.append(Config.Path.basePath)
        let test = Python.import("example")
        let response = test.hello()
        print(response)
    }
}

example.py

import pandas

def hello():
    return "Hello Python"

Error:

PythonKit/Python.swift:706: Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'pandas'

1 Answer 1

0

Figured it out that I had pandas install in the wrong Python version.

$ python3.11 -m pip install pandas

fixed it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.