首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在Mac M1中导入python中的pdftotext

无法在Mac M1中导入python中的pdftotext
EN

Stack Overflow用户
提问于 2022-03-06 15:55:42
回答 1查看 573关注 0票数 -1

我不能在新的mac M1中导入pdftext。我采取的步骤是:

  1. 安装python 3.10

  1. 安装命令行开发工具

  1. pip3 install pdftotext来自

终端

import pdftotext类型的

  1. 打开空闲

  1. I得到以下错误:

回溯(最近一次调用):文件"",第1行,在导入pdftotext ImportError:'_ZN7poppler24set_debug_error_functionEPFvRKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEPvES9' 0x0002中):在平面命名空间‘_ZN7poppler24set_debug_error_functionEPFvRKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEPvES9’中找不到符号

我已经花了几个小时搜索这条错误消息。

有什么建议吗?

PS:我已经尝试了其他几个pdf ->文本包,但他们没有阅读完整的pdf。由于一些奇怪的原因,我需要阅读的pdfs非常复杂,而且许多包没有完全读取它们。pdftotext有因此,我需要的是帮助使这个pdftotext工作。

EN

回答 1

Stack Overflow用户

发布于 2022-03-06 16:05:15

我不认为pdftotext是个好图书馆。更好地使用PyPDF2,下面是示例

代码语言:javascript
复制
import PyPDF2
 
#create file object variable
#opening method will be rb
pdffileobj=open('1.pdf','rb')
 
#create reader variable that will read the pdffileobj
pdfreader=PyPDF2.PdfFileReader(pdffileobj)
 
#This will store the number of pages of this pdf file
x=pdfreader.numPages
 
#create a variable that will select the selected number of pages
pageobj=pdfreader.getPage(x+1)
 
#(x+1) because python indentation starts with 0.
#create text variable which will store all text datafrom pdf file
text=pageobj.extractText()
 
#save the extracted data from pdf to a txt file
#we will use file handling here
#dont forget to put r before you put the file path
#go to the file location copy the path by right clicking on the file
#click properties and copy the location path and paste it here.
#put "\\your_txtfilename"
file1=open(r"C:\Users\SIDDHI\AppData\Local\Programs\Python\Python38\\1.txt","a")
file1.writelines(text)
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71371871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档