提问人:sancokai 提问时间:11/17/2023 最后编辑:HangarRashsancokai 更新时间:11/17/2023 访问量:33
在 iOS 应用程序中导入 pdfminer/tabula
Importation of pdfminer/tabula in an iOS app
问:
我正在开发一个 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")
}
如果您能提供任何帮助或建议来帮助解决此问题,我将不胜感激。
答: 暂无答案
下一个:Verilog - 负数除法
评论