[英]pypdf2 is not defined
new to python 3.7 version.新的python 3.7版本。 Trying to use
pypdf2
but I have an error that I can't fix by myself:尝试使用
pypdf2
但我有一个我自己无法修复的错误:
my comand:我的命令:
pdfFile2 = open(r"C:\Users\Luca\Desktop\python\tutorial\doc2.pdf", "wb") # w=write, r=read, b=binary
writer1 = pyPDF2.PdfFileWriter()
The error: Traceback (most recent call last): File "C:/Users/Luca/Desktop/python/tutorial/tutorial.py", line 8, in <module> 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
I have installed the pypdf2
library but I cant go on, how can I fix this?我已经安装了
pypdf2
库,但我无法继续,我该如何解决这个问题?
Step 1: PyPDF2 is a pure Python package, so you can install it using pip (assuming pip is in your system's path):第 1 步:PyPDF2 是一个纯 Python 包,因此您可以使用 pip 安装它(假设 pip 在您的系统路径中):
python -m pip install pypdf2
python -m pip install pypdf2
Step 2: Once you install that packages.第 2 步:安装这些软件包后。 You can import the specific packages like PdfFileReader & PdfFileWriter from that library.
您可以从该库中导入特定的包,如PdfFileReader和PdfFileWriter 。
from PyPDF2 import PdfFileReader, PdfFileWriter
从 PyPDF2 导入 PdfFileReader、PdfFileWriter
Step 3: Finally, you can instantized that module object directly第 3 步:最后,您可以直接实例化该模块对象
# For Reader # 给读者
reader= PdfFileReader (open("fpath",'rb'))
reader = PdfFileReader (open("fpath",'rb'))
# For Write # 对于写
writer= PdfFileWriter ()
作家= PdfFileWriter ()
outfp=open("outpath",'wb')outfp=open("outpath",'wb')
writer.write(outfp)writer.write(outfp)
Doc: https://pythonhosted.org/PyPDF2/PdfFileWriter.html文档: https : //pythonhosted.org/PyPDF2/PdfFileWriter.html
这很可能发生,因为您的示例在代码的第二行中使用pyPDF2
(小p
)而不是PyPDF2
(大写P
)。
NameError Traceback (most recent call last) in ----> 1 pdfReader = pypdf2.PdfFileReader(filename) ----> 1中的NameError追溯(最近一次呼叫最近)= pdfReader = pypdf2.PdfFileReader(filename)
NameError: name 'pypdf2' is not defined NameError:名称“ pypdf2”未定义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.