简体   繁体   中英

'import pyPDF2' results in 'ModuleNotFoundError'

Summary of problem: Using the python interpreter, I type import pyPDF2 and get a ModuleNotFound error even though I have installed the pyPDF2 module:

>>> import pyPDF2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'

What I have tried: I am using Windows 10. I am new to python. I have installed Python 3.8.3 to a C:\Python38 folder. I have installed pyPDF2 via 'pip install pyPDF2'. The windows path includes the folders: C:\Python38\Scripts\;C:\Python38\ .

At the windows Command Prompt I type 'python' and get:

c:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 

At the python interpreter prompt I type 'import pyPDF2' and get:

>>> import pyPDF2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyPDF2'
>>>

Note: There is installed an old version of python 2.7 from an ArcGIS install. Could that be causing a conflict? If not, I would rather not uninstall that version since it goes with ArcGIS, which I use.

What I am really trying to do is to automate the concatenation of 7,696 pdf files into 104 pdf files. So far my program looks like this:

import os
from pyPDF2 import PdfFileMerger

source_dir = os.getcwd()

merger = PdfFileMerger()

for item in os.listdir(source_dir):
    if item.beginswith('District001_Pg'):
        merger.append(item)

merger.write('District001.pdf')
merger.close()

Any help anyone is able to provide will be greatly appreciated!

If you want to run 2 different versions of python in the same machine without having conflicts, you can use VirtualEnv. Here is a document which I found on the web to get you started. https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/

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