简体   繁体   中英

No module named 'PyPDF2' When Trying to Import

I am attempting to Import PyPDF2 in order to read a PDF file and parse through it. I am using a Raspberry Pi, and have installed PyPDF2 using the command pip install PyPDF2 . However, when I try importing it, I am getting ModuleNotFoundError.

I think it may have installed it into the wrong location. When I do python -V it says I am using version 2.7.16. But the error states it's trying to look into the python3 folder?

I am attempting to import it using the line import PyPDF2

The error I'm getting is:

Traceback (most recent call last):
  File "/home/pi/SqlDatabase.py", line 5, in <module>
    import PyPDF2
  File "/usr/lib/python3/dist-packages/thonny/backend.py", line 305, in _custom_import
    module = self._original_import(*args, **kw)
ModuleNotFoundError: No module named 'PyPDF2'

Any idea of how I can install PyPDF into the correct directory, or perhaps a different solution?

如果您使用 python3 启动程序(例如查看文件的第一行是否有#!/usr/bin/python3或类似的),您需要使用pip3安装库。

It seems that you have not installed PyPDF2 module in your device.

Execute following code in your terminal:

pip install PyPDF2

or

pip3 install PyPDF2

I think this will solve your problem. If this does not solve your problem, then there may be problem in your directory of python.

I have also faced the same issue. Note that Python is a case-sensitive language. While using the import command use PyPDF2 and not pyPDF2

To install:

pipenv install PyPDF2

To import:

import PyPDF2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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