ImportError 没有名为 'PyPDF2' 的模块
ImportError No Module Named 'PyPDF2'
Python 的新手...,实际上是一般编程的新手,所以请多多包涵。在 Ubuntu 20.04(是的,也是 Linux 的新手)和 Python 3.8.2
我正在尝试 运行 使用 PyPDF2 的脚本。我能够很好地安装它:
sudo apt-get install python3-pypdf2
我可以从命令行导入它而不会出现任何错误:
import PyPDF2
当我尝试从 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'
这是我正在使用的脚本。
从 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)
这里可能遗漏了一些明显的东西,但我们将不胜感激。
首先你应该通过 pip 安装 python 包。 运行 pip install PyPDF2
,这可能已经解决了。
还要检查在 pycharm 中为您的项目选择了哪个解释器。如果 Pycharm 没有使用您的系统 python,它不会看到从正常 shell.
安装的软件包
您会在 Settings -> Project: your_project -> Project Interpreter
中找到它。
Python 的新手...,实际上是一般编程的新手,所以请多多包涵。在 Ubuntu 20.04(是的,也是 Linux 的新手)和 Python 3.8.2
我正在尝试 运行 使用 PyPDF2 的脚本。我能够很好地安装它:
sudo apt-get install python3-pypdf2
我可以从命令行导入它而不会出现任何错误:
import PyPDF2
当我尝试从 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'
这是我正在使用的脚本。
从 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)
这里可能遗漏了一些明显的东西,但我们将不胜感激。
首先你应该通过 pip 安装 python 包。 运行 pip install PyPDF2
,这可能已经解决了。
还要检查在 pycharm 中为您的项目选择了哪个解释器。如果 Pycharm 没有使用您的系统 python,它不会看到从正常 shell.
安装的软件包您会在 Settings -> Project: your_project -> Project Interpreter
中找到它。