0

This is my code and I get this error ModuleNotFoundError: No module named 'pyPDF2'.

I've already installed with pip instal pyPDF2.
If I try it again it says:

C:\Users\nicks\Desktop\Coding Projects\Python\Pdf to Audio›pip install PyPDF2
Requirement already satisfied: PyPDF2 in c: \users\nicks\appdata\local\packages \pythonsoftwarefoundation.python.3.9 qbz5n2kfra8p@\localcache\local
-packages \python39 \site-packages (1.26.0)
import pyPDF2

pdf = open('material.pdf','rb')
pdfReader = pyPDF2.PdFileReader(pdf)
speaker = pyttsx3.init()
speaker.say(pdf)
speaker.save_to_file(string, 'material.mp3')
speaker.runAndWait

I use Python 3.9.10.

BlackFox
  • 773
  • 1
  • 8
  • 24
Nick S
  • 1
  • 3

1 Answers1

0
!pip install install pypdf2
from PyPDF2 import PdfFileReader
with open('material.pdf', 'rb') as f:
    pdf = PdfFileReader(f)
    pdf

On changing the library name to 'pypdf2' from 'pyPDF2', it didn't give me any nomodule error. I referred to the below link for this solution. See if it helps? :) https://realpython.com/pdf-python/

Francis Sunny
  • 36
  • 1
  • 6
  • Also, `import sys !{sys.executable} -m pip install PyPDF2` was one of a suggestion in the another post in the below link https://stackoverflow.com/questions/39241643/no-module-named-pypdf2-error – Francis Sunny Mar 13 '22 at 22:12
  • If you are using Jupyter or IPython, please update your approaches going forward to use the magic commands `%pip install` or `%conda install`. Or leave off the exclamation point and let automagics handle it. The modern magics commands help insure the installation occurs in the environment backing the current source. Use of `!pip` or `!conda` is outdated. Please see [here](https://discourse.jupyter.org/t/why-users-can-install-modules-from-pip-but-not-from-conda/10722/4?u=fomightez) for more about the current best practices around this issue in Jupyter/IPython. – Wayne Mar 13 '22 at 22:18
  • `!pip install...` is not valid in a Python file. OP didn't mention anything about using Jupyter or iPython. – ChrisGPT was on strike Mar 13 '22 at 23:22
  • Yes, but @FrancisSunny included the exclamation point, and so I assume he was using IPython or Jupyter. – Wayne Mar 13 '22 at 23:26
  • The appropriate variant of `python -m pip install ` is usually good when using Python without IPython/Jupyter. – Wayne Mar 13 '22 at 23:33