未定义pypdf2

2024-09-30 03:23:08 发布

您现在位置:Python中文网/ 问答频道 /正文

Python3.7版本的新增功能。 正在尝试使用pypdf2,但我有一个无法自行修复的错误:

我的命令:

pdfFile2 = open(r"C:\Users\Luca\Desktop\python\tutorial\doc2.pdf", "wb")  # w=write, r=read, b=binary
writer1 = pyPDF2.PdfFileWriter()

错误: Traceback (most recent call last): File "C:/Users/Luca/Desktop/python/tutorial/tutorial.py", line 8, in <module> writer1 = pyPDF2.PdfFileWriter()

NameError: name 'pyPDF2' is not defined

我已经安装了pypdf2库,但是我不能继续,我该如何修复它?在


Tags: 命令功能版本错误openuserstutorialluca
2条回答

这很可能是因为您的示例在代码的第二行使用了pyPDF2(smallp),而不是PyPDF2(大写P)。在

第一步: PyPDF2是一个纯Python包,因此可以使用pip安装它(假设pip位于系统路径中):

python -m pip install pypdf2

第二步: 一旦你安装了这些软件包。 您可以从该库导入特定的包,如PdfFileReaderPdfFileWriter。在

from PyPDF2 import PdfFileReader, PdfFileWriter

第三步: 最后,可以直接实例化该模块对象

#供读者阅读

reader=PdfFileReader(open("fpath",'rb'))

#用于写入

writer=PdfFileWriter()
outfp=open("outpath",'wb')
writer.write(outfp)

文件:https://pythonhosted.org/PyPDF2/PdfFileWriter.html

相关问题 更多 >

    热门问题