在 iOS 应用程序中导入 pdfminer/tabula

Importation of pdfminer/tabula in an iOS app

提问人:sancokai 提问时间:11/17/2023 最后编辑:HangarRashsancokai 更新时间:11/17/2023 访问量:33

问:

我正在开发一个 iOS 应用程序,在导入 pdfplumber 时遇到了困难。我已将 Python 集成到我的应用程序中。一切正常,我可以毫无问题地从 Swift 执行 Python 程序。但是,在导入某些 Python 库时,它们通常依赖于其他库。在本例中,它是链接到“pdfminer”的“pdfplumber”。

不幸的是,pdfminer无法正确导入,并给了我以下错误代码:

错误:Python 异常:无法从“pdfminer.pdfinterp”导入名称“PDFStackT”。

我也尝试切换到 tabula,但在导入 numpy 时遇到了问题。错误代码为:

错误:Python 异常:导入 numpy 时出错:不应尝试从其源目录导入 numpy;请退出 numpy 源代码树,然后从那里重新启动 Python 解释器。

当我初始化 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()
}

以及我调用 Python 脚本时的代码:

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")
}

如果您能提供任何帮助或建议来帮助解决此问题,我将不胜感激。

there is the disposition of the files

蟒蛇 numpy pdfplumber swift-pythonkit

评论

0赞 Dávid Pásztor 11/17/2023
您需要编辑您的问题,以文本形式包含所有相关代码,使用正确的代码格式 - 而不是屏幕截图 - 以最小的可重现示例的形式,以使问题切合主题。
0赞 sancokai 11/17/2023
对不起,我的错,这是我第一次在 StackOverflow 上......谢谢建议

答: 暂无答案