I have a project on iOS using Xcode 14. I use Python-apple-support and PythonKit to implement Python in my project. When I use PythonKit to import numpy modules in this way:

import SwiftUI
import Python
import PythonKit
@main
struct pppppApp: App {
    init() {
        fakelink()
    }
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
    func fakelink() {
        guard let stdLibPath = Bundle.main.path(forResource: "python-stdlib", ofType: nil) else { return }
        guard let libDynloadPath = Bundle.main.path(forResource: "python-stdlib/lib-dynload", ofType: nil) else { return }
        setenv("PYTHONPATH", "\(stdLibPath):\(libDynloadPath):\("/usr/local/lib/python3.9/site-packages")", 1)
        Py_Initialize()
        _ = Python.import("numpy")
    }
}

I got this error:

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

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/Users/wanzongnynsmac/Library/Developer/CoreSimulator/Devices/2E1F3AAB-D569-4729-98CC-D7CD98254B14/data/Containers/Bundle/Application/5CEBB86A-59FD-43F6-8223-30385169578B/ppppp.app/ppppp"
  * The NumPy version is: "1.25.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

Traceback:
  File "/usr/local/lib/python3.9/site-packages/numpy/__init__.py", line 139, in <module>
    from . import core
  File "/usr/local/lib/python3.9/site-packages/numpy/core/__init__.py", line 49, in <module>
    raise ImportError(msg)

I tried to change the python-apple-support version and numpy version several times, but nothing worked. Can anyone help me please?

0

There are 0 best solutions below