首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义pypdf2

未定义pypdf2
EN

Stack Overflow用户
提问于 2018-07-10 21:19:30
回答 2查看 4.9K关注 0票数 1

新增python3.7版本。尝试使用pypdf2,但我有一个错误无法自己修复:

我的伯爵:

代码语言:javascript
复制
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库,但我不能继续,我如何解决这个问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-05 03:40:11

步骤1: PyPDF2是一个纯package,所以您可以使用pip安装它(假设pip在您的系统路径中):

python安装-m pypdf2

第二步:一旦你安装了软件包。您可以从该库中导入特定的包,如PdfFileReader & PdfFileWriter。

从PyPDF2 import PdfFileReader,PdfFileWriter

步骤3:最后,您可以直接实例化该模块对象。

为读者

( reader=PdfFileReader(open("fpath",‘rb’)

写用

writer=PdfFileWriter() Outfp=open(“外部路径”,'wb') writer.write(outfp)

医生:https://pythonhosted.org/PyPDF2/PdfFileWriter.html

票数 3
EN

Stack Overflow用户

发布于 2018-07-10 22:10:52

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51274042

复制
相关文章

相似问题

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