pypdf2没有定义

问题描述 投票:0回答:2

新的Python 3.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库,但我不能去,我怎么能解决这个问题?

python pypdf2
2个回答
0
投票

第1步:PyPDF2是一个纯Python包,这样你就可以使用画中画(PIP假设您的系统中的路径)安装:

蟒蛇-m PIP安装pypdf2

第2步:一旦你安装的软件包。您可以从库中导入像PdfFileReader&PdfFileWriter的特定软件包。

从PyPDF2进口PdfFileReader,PdfFileWriter

步骤3:最后,你可以直接速溶该模块对象

#对于读者

读者= PdfFileReader(开( “fpath”, 'RB'))

#对于写

作家= PdfFileWriter() outfp =打开( “outpath中”, 'WB') writer.write(outfp)

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


0
投票

因为您的示例使用pyPDF2(小p),而不是PyPDF2(资本P)在你的代码的第二行这是发生的可能性最大。

© www.soinside.com 2019 - 2024. All rights reserved.