简体   繁体   English

ImportError 没有名为“PyPDF2”的模块

[英]ImportError No Module Named 'PyPDF2'

New to Python..., well actually new to programming in general, so pls bear with me. Python 的新手...,实际上对一般编程很陌生,所以请多多包涵。 On Ubuntu 20.04 (yes, new to Linux as well) with Python 3.8.2在 Ubuntu 20.04 上(是的,Linux 的新功能)和 Python 3.8.2

I'm trying to run a script that uses PyPDF2.我正在尝试运行使用 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: sudo apt-get install python3-pypdf2我可以从命令行导入它而不会出现任何错误:

import PyPDF2

When i try to import it from Pycharm, however, it generates a ModuleNotFoundError error:但是,当我尝试从 Pycharm 导入它时,它会生成 ModuleNotFoundError 错误:

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从 PyPDF2 导入 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.可能在这里遗漏了一些明显的东西,但任何帮助将不胜感激。

First of all you should install python packages via pip.首先你应该通过 pip 安装 python 包。 Run pip install PyPDF2 , that might fix it already.运行pip install PyPDF2 ,这可能已经修复它。

Also check which interpreter is selected for your project in pycharm.还要检查在 pycharm 中为您的项目选择了哪个解释器。 If Pycharm isn't using your system python, it won't see packages installed from a normal shell.如果 Pycharm 没有使用您的系统 python,它将看不到从普通 shell 安装的软件包。

You'll find it in the Settings -> Project: your_project -> Project Interpreter .您可以在Settings -> Project: your_project -> Project Interpreter中找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM