Forums

how to activate the PyPDF2 module

I try and run these lines of code : 1 pdf_file=open("e.pdf","rb") 2 read_pdf=PyPDF2.PdfFileReader(pdf_file)

and it gives me this message errorread_pdf=PyPDF2.PdfFileReader(pdf.file) NameError: name 'PyPDF2' is not defined

What am I doing wrong?

You'll need to use the appropriate version of the pip Bash command to install it -- for example, if you're using Python 3.6, you should use pip3.6 install --user PyPDF2. Check out this help page for more details and some alternative ways of installing new modules.

I started a bash console entered the code and it seemed to install "Successfully built PyPDF2 Installing collected packages: PyPDF2 Successfully installed PyPDF2-1.26.0 16:42 /home $ "

I went back and ran the code again I still get this message NameError: name 'PyPDF2' is not defined

I must be missing a step somewhere.

How are you running the program that's showing that error? If it's using the "Save and run" button in the editor, could you try running exit() in the console there, then running it again? It's possible that once it's decided that a module cannot be found, it's remembering that and not looking for it again once you've installed it; creating a new console by exiting the old one then re-running should bypass that.

Yes that did work, closing the console and opening another one did not give an error when I ran the line of code. It does work now. The string created by using this module did not give the best looking results so I will have to work on that.

Syntax error in python 3.8 for pip install PyPDF2 What should I do?

Run the command in a Bash console, not in the Python REPL.