Importation of pdfminer/tabula in an iOS app

98 views Asked by At

I am working on the development of an iOS application and I am encountering difficulties when importing pdfplumber. I have integrated Python into my application. Everything is working fine and I can execute Python programs from Swift without any issues. However, when importing certain Python libraries, they often have dependencies on other libraries. In this case, it's "pdfplumber" linked to "pdfminer."

Unfortunately, pdfminer does not import correctly and gives me the following error code:

Error: Python exception: cannot import name 'PDFStackT' from 'pdfminer.pdfinterp'.

I also tried switching to tabula, but I encounter a problem when importing numpy. The error code is:

Error: Python exception: 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.

There is the code when I initialise Python:

func testView() {

    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 }
    guard let libDocPath = Bundle.main.path(forResource: "python-stdlib/ExtraLib", ofType: nil) else { return }
    let numpyLibPath = "/Users/sancokai/Desktop/ABP app/ABP app/numpy_doc"
    setenv("PYTHONHOME", stdLibPath, 1)
    setenv("PYTHONPATH", "\(stdLibPath):\(libDynloadPath):\(libDocPath):\(numpyLibPath)", 1)
    
    Py_Initialize()
    extractDataFromPDF()
}

and the code when I call my Python scripts:

func extractDataFromPDF() {

    let sys = Python.import("sys")
    do {
        sys.path.append("/Users/sancokai/Desktop/ABP app/ABP app/Py-embed")
        let pdfExtractor = try Python.attemptImport("extract")
        try pdfExtractor.tabula.read_pdf("exemple")
        print("Extract table success")
    } catch {
        print("Error: \(error)")
    }
    print("end of extract")
}

I would be grateful for any help or advice you could provide to help resolve this issue.

there is the disposition of the files

0

There are 0 answers