简体   繁体   English

“导入 pyPDF2”导致“ModuleNotFoundError”

[英]'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:问题摘要:使用 python 解释器,我输入import pyPDF2并收到 ModuleNotFound 错误,即使我已经安装了 pyPDF2 模块:

>>> 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.我尝试了什么:我正在使用 Windows 10。我是 python 的新手。我已经将 Python 3.8.3 安装到C:\Python38文件夹中。 I have installed pyPDF2 via 'pip install pyPDF2'.我已经通过“pip install pyPDF2”安装了pyPDF2 The windows path includes the folders: C:\Python38\Scripts\;C:\Python38\ . windows 路径包括以下文件夹: C:\Python38\Scripts\;C:\Python38\

At the windows Command Prompt I type 'python' and get:在 windows 命令提示符下,我输入“python”并得到:

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:在 python 解释器提示符下,我键入“import pyPDF2”并得到:

>>> 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.注意:从 ArcGIS 安装中安装了旧版本 python 2.7。 Could that be causing a conflict?这会引起冲突吗? If not, I would rather not uninstall that version since it goes with ArcGIS, which I use.如果没有,我宁愿不卸载该版本,因为它与我使用的 ArcGIS 一起使用。

What I am really trying to do is to automate the concatenation of 7,696 pdf files into 104 pdf files.我真正想做的是将 7,696 个 pdf 个文件自动串联成 104 个 pdf 个文件。 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.如果你想在同一台机器上运行 2 个不同版本的 python 而不会发生冲突,你可以使用 VirtualEnv。 Here is a document which I found on the web to get you started.这是我在 web 上找到的文档,可帮助您入门。 https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/ https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/

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

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