1

New to Python..., well actually new to programming in general, so pls bear with me. On Ubuntu 20.04 (yes, new to Linux as well) with Python 3.8.2

I'm trying to run a script that uses PyPDF2. I was able to install it just fine with:

sudo apt-get install python3-pypdf2 and I can import it from the command line without any error:

import PyPDF2

When i try to import it from Pycharm, however, it generates a ModuleNotFoundError error:

Traceback (most recent call last):
  File "/home/surista/.config/JetBrains/PyCharm2020.1/scratches/scratch_2.py", line 1, in <module>
    from PyPDF2 import PdfFileReader
ModuleNotFoundError: No module named 'PyPDF2'

Here's the script I'm using.

from PyPDF2 import PdfFileReader

def get_info(path):
    with open(path, 'rb') as f:
        pdf = PDFFileReader(f)
        info = pdf.getDocumentInfo()
        number_of_pages = pdf.getNumPages()

    print(info)

    author = info.author
    creator = info.creator
    producer = info.producer
    subject = info.subject
    title = info.title

if __name__ == '__main__':
    path = '/home/surista/Documents/pdfs/test_eng-1.pdf'
    get_info(path)

Probably missing something obvious here, but any help would be appreciated.

1 Answer 1

3

First of all you should install python packages via pip. Run pip install PyPDF2, that might fix it already.

Also check which interpreter is selected for your project in pycharm. If Pycharm isn't using your system python, it won't see packages installed from a normal shell.

You'll find it in the Settings -> Project: your_project -> Project Interpreter.

Sign up to request clarification or add additional context in comments.

4 Comments

Txs. pip3 install PyPDF2 resulted in: Requirement already satisfied: PyPDF2 in /usr/local/lib/python3.8/dist-packages (1.26.0) I forgot to mention that I did check the python interpreter. It's currently listed as Python 3.8 (Pong) ~/PycharmProjects/Pong/venv/bin/python
I'm willing to bet that the pip/python you're getting in your shell is another one. Try a which pip and see if it lines up.
OK, i was actually able to update the interpreter to the system interpreter, as you suspected that seemed to be the problem, got it working now. Many thanks! Very sorry that my upvote won't be displayed....
Glad I could help! Feel free to accept my answer ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.