No module named 'PyPDF2' When Trying to Import

Question:

I am attempting to Import PyPDF2 in order to read a PDF file and parse through it. I am using a Raspberry Pi, and have installed PyPDF2 using the command pip install PyPDF2. However, when I try importing it, I am getting ModuleNotFoundError.

I think it may have installed it into the wrong location. When I do python -V it says I am using version 2.7.16. But the error states it’s trying to look into the python3 folder?

I am attempting to import it using the line import PyPDF2

The error I’m getting is:

Traceback (most recent call last):
  File "/home/pi/SqlDatabase.py", line 5, in <module>
    import PyPDF2
  File "/usr/lib/python3/dist-packages/thonny/backend.py", line 305, in _custom_import
    module = self._original_import(*args, **kw)
ModuleNotFoundError: No module named 'PyPDF2'

Any idea of how I can install PyPDF into the correct directory, or perhaps a different solution?

Asked By: something17

||

Answers:

If you are starting the program with python3 (e.g. see if the first line of the file has #!/usr/bin/python3 or similar), you need to install the library with pip3.

Answered By: Ivan Voras

It seems that you have not installed PyPDF2 module in your device.

Execute following code in your terminal:

pip install PyPDF2

or

pip3 install PyPDF2

I think this will solve your problem. If this does not solve your problem, then there may be problem in your directory of python.

Answered By: Rohit Joshi

I have also faced the same issue. Note that Python is a case-sensitive language.
While using the import command use PyPDF2 and not pyPDF2

To install:

pipenv install PyPDF2

To import:

import PyPDF2
Answered By: Nidhi Gupta

SOLVED! I faced the same problem. I installed used pip3, pip everything. But successfully running after installing from below command:

pipenv install PyPDF2