[Python] ImportError: cannot import name 'PdfReader' from 'PyPDF2'

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I installed the PyPDF2 package using pip and got the following message after the installation:

    !pip install PyPDF2


    Collecting PyPDF2
    Downloading PyPDF2-2.11.1-py3-none-any.whl (220 kB)
    -------------------------------------- 220.4/220.4 kB 2.7 MB/s eta 0:00:00
    Requirement already satisfied: typing-extensions>=3.10.0.0 in c:\users\dell\appdata\local\programs\python\python37\lib\site-packages (from PyPDF2) (3.10.0.2)
    Installing collected packages: PyPDF2
    Successfully installed PyPDF2-2.11.1
    ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
    camelot-py 0.10.1 requires openpyxl>=2.5.8, which is not installed.


    I imported PdfReader and ran the following code:

    from PyPDF2 import PdfReader

    reader = PdfReader(r"D:\Sample.pdf")
    for page in reader.pages:
    for image in page.images:
    with open(image.name, "wb") as fp:
    fp.write(image.data)


    But, I get an "ImportError":

    ---------------------------------------------------------------------------
    ImportError Traceback (most recent call last)
    ~\AppData\Local\Temp/ipykernel_19816/3180674727.py in <module>
    ----> 1 from PyPDF2 import PdfReader
    2
    3 reader = PdfReader(r"D:\Sample.pdf")
    4 for page in reader.pages:
    5 for image in page.images:

    ImportError: cannot import name 'PdfReader' from 'PyPDF2' (C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\PyPDF2\__init__.py)


    Any inputs on how to resolve this issue?

    Continue reading...

Compartilhe esta Página