简体   繁体   中英

pypdf2 is not defined

new to python 3.7 version. Trying to use pypdf2 but I have an error that I can't fix by myself:

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()

NameError: name 'pyPDF2' is not defined

I have installed the pypdf2 library but I cant go on, how can I fix this?

Step 1: PyPDF2 is a pure Python package, so you can install it using pip (assuming pip is in your system's path):

python -m pip install pypdf2

Step 2: Once you install that packages. You can import the specific packages like PdfFileReader & PdfFileWriter from that library.

from PyPDF2 import PdfFileReader, PdfFileWriter

Step 3: Finally, you can instantized that module object directly

# For Reader

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

# For Write

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

Doc: https://pythonhosted.org/PyPDF2/PdfFileWriter.html

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

NameError Traceback (most recent call last) in ----> 1 pdfReader = pypdf2.PdfFileReader(filename)

NameError: name 'pypdf2' is not defined

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM