Python-iOS icon indicating copy to clipboard operation
Python-iOS copied to clipboard

How to install numpy as an additional packages?

Open Anmol-SoC opened this issue 10 months ago • 0 comments

Hi, I have tried installing numpy and gave the installed numpy path but every time I run the code I am getting this error -> ImportError: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there.

This is the code I am running ->

func runPythonCode() {
    // Initialize the Python interpreter
    Py_Initialize()
    let pythonModulesPath = "/Users/anmol.varshney/Documents/python_modules/"
    
    // Python code as a string
    let pythonCode = """
    import sys
    sys.path.append('\(pythonModulesPath)')
    import numpy as np
    array1 = np.array([1, 2, 3, 4, 5])
    array2 = np.array([10, 20, 30, 40, 50])
    print(array1)
    print('Hello from Python!')
    """
    
    // Execute the Python code
    pythonCode.withCString { cString in
        PyRun_SimpleString(cString)
    }
    
    // Finalize the Python interpreter
    Py_Finalize()
}

Please help me how to import numpy or any 3rd party python packages in this?

Anmol-SoC avatar Dec 13 '24 10:12 Anmol-SoC