[英]pypdf2 is not defined
新的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
库,但我无法继续,我该如何解决这个问题?
第 1 步:PyPDF2 是一个纯 Python 包,因此您可以使用 pip 安装它(假设 pip 在您的系统路径中):
python -m pip install pypdf2
第 2 步:安装这些软件包后。 您可以从该库中导入特定的包,如PdfFileReader和PdfFileWriter 。
从 PyPDF2 导入 PdfFileReader、PdfFileWriter
第 3 步:最后,您可以直接实例化该模块对象
# 给读者
reader = PdfFileReader (open("fpath",'rb'))
# 对于写
作家= PdfFileWriter ()
outfp=open("outpath",'wb')
writer.write(outfp)
这很可能发生,因为您的示例在代码的第二行中使用pyPDF2
(小p
)而不是PyPDF2
(大写P
)。
----> 1中的NameError追溯(最近一次呼叫最近)= pdfReader = pypdf2.PdfFileReader(filename)
NameError:名称“ pypdf2”未定义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.