Python “没有名为 PyPDF2 的模块”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39241643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"no module named PyPDF2" error
提问by ALisboa
I use Spyder, with Python 2.7, on a windows 10. I was able to install the PyPDF2 package with a conda command from my prompt. I said installation complete. Yet, If I try to run a simple import command:
我在 Windows 10 上使用带有 Python 2.7 的 Spyder。我能够从我的提示中使用 conda 命令安装 PyPDF2 包。我说安装完成。然而,如果我尝试运行一个简单的导入命令:
import PyPDF2
import PyPDF2
I get the error:
我收到错误:
ImportError: No module named PyPDF2
ImportError: No module named PyPDF2
How can I fix this?
我怎样才能解决这个问题?
回答by Junior Usca
If you use python3 maybe
如果你使用 python3 也许
apt-get install python3-pypdf2
回答by Ashutosh Chamoli
In my case, I was trying to import 'pyPdf2' instead of 'PyPDF2'. Observe the case.
就我而言,我试图导入“pyPdf2”而不是“PyPDF2”。观察情况。
import PyPDF2
导入 PyPDF2
is correct.
是正确的。
回答by darla_sud
I faced the same problem. But, In my case,
我遇到了同样的问题。但是,就我而言,
I previously installed Python3separately from official website and was using without any issues
Then later I installed Anacondapackage distribution software which itself has another Python3 installed in corresponding directory.
So, when I installed PyPDF2, it installed normally and while importing throws an error, because the base path of python3 was changed to be used with Anaconda.
所以,当我安装 PyPDF2 时,它安装正常,并且在导入时抛出错误,因为 python3 的基本路径已更改为与 Anaconda 一起使用。
Then I opened Anaconda prompt and installed PyPDF2 there and tried to import. It worked!!
然后我打开 Anaconda prompt 并在那里安装 PyPDF2 并尝试导入。有效!!
Then I can use it from any command prompt in my Windows PC. Or else you can delete Anaconda and everything works normally. Its just a conflict of two pythons in my pc.
然后我可以从我的 Windows PC 中的任何命令提示符使用它。否则,您可以删除 Anaconda,一切正常。它只是我电脑中两条蟒蛇的冲突。
Conclusion: Try any overlapping softwares in your PC(in my case Anaconda prompt) and try their CMD to install packages and import. If I wanted to install any package I have to go to Anaconda prompt and install it and importing that modules works anywhere without any error. So from now on wards I'm only using Anaconda prompt as my default installation prompt.
结论:在您的 PC 中尝试任何重叠的软件(在我的情况下是 Anaconda 提示符)并尝试使用它们的 CMD 来安装包和导入。如果我想安装任何包,我必须转到 Anaconda 提示符并安装它并导入该模块在任何地方都可以正常工作而不会出现任何错误。所以从现在开始,我只使用 Anaconda 提示作为我的默认安装提示。
回答by heytherebrowncow
This is the case which I followed for python3. For python2 try with pip:
这就是我在 python3 中遵循的情况。对于 python2 尝试使用 pip:
pip install PyPDF2
回答by Jason
I had this problem too when I tried to import PyPDF2 like this:
当我尝试像这样导入 PyPDF2 时,我也遇到了这个问题:
sudo apt-get install python-pypdf2
sudo apt-get install python-pypdf2
When running some simple script with import PyPDF2
, I would get an error like this:
当使用 运行一些简单的脚本时import PyPDF2
,我会收到这样的错误:
ImportError: No module named PyPDF2
ImportError: No module named PyPDF2
The solution was to also install pdfmerge, like this:
解决方案是还安装 pdfmerge,如下所示:
pip install pdfmerge
pip install pdfmerge
回答by Gabriel Staples
How to install Python packages on Windows for various versions of Python which are simultaneously installed:
如何在 Windows 上为同时安装的各种版本的 Python 安装 Python 包:
I have multiple versions of Python installed on my Windows 8.1 machine (Python 2.7, 3.5, and 3.7). This created problems (confusion, I should say). You must therefore be very explicit when installing packages.Ex:
我的 Windows 8.1 机器上安装了多个版本的 Python(Python 2.7、3.5 和 3.7)。这造成了问题(我应该说是混乱)。因此,您在安装软件包时必须非常明确。前任:
py -3.7 -m pip install PyPDF2
INSTEAD OF:
代替:
pip install PyPDF2
or pip3 install PyPDF2
pip install PyPDF2
或者 pip3 install PyPDF2
And to upgrade pip, use:
而升级点子,使用方法:
py -3.7 -m pip install --upgrade pip
INSTEAD OF:
代替:
py -3 -m pip install --upgrade pip
py -3 -m pip install --upgrade pip
Now, I can run python 3.7with py -3.7
, and since I did py -3.7 -m pip install PyPDF2
the import PyPDF2
command works! Previously, since I had only done pip3 install PyPDF2
, the import PyPDF2
command only worked if I ran py -3.5
, oddly enough. I think it has something to do with the fact that I installed Python 3.5 for all users, but Python 3.7 for only my user account, so the different pip install
commands were placing the installed packages into different locations.
现在,我可以运行 python 3.7了py -3.7
,因为我做py -3.7 -m pip install PyPDF2
了import PyPDF2
命令工作!以前,由于我只完成了pip3 install PyPDF2
,所以该import PyPDF2
命令仅在我运行时才起作用py -3.5
,这很奇怪。我认为这与我为所有用户安装了 Python 3.5 而仅为我的用户帐户安装了 Python 3.7 的事实有关,因此不同的pip install
命令将已安装的包放置到不同的位置。
See more here: https://docs.python.org/3/installing/index.html
在此处查看更多信息:https: //docs.python.org/3/installing/index.html
Ex:
前任:
On Windows, use the py Python launcher in combination with the -m switch:
py -2 -m pip install SomePackage # default Python 2 py -2.7 -m pip install SomePackage # specifically Python 2.7 py -3 -m pip install SomePackage # default Python 3 py -3.4 -m pip install SomePackage # specifically Python 3.4
在 Windows 上,将 py Python 启动器与 -m 开关结合使用:
py -2 -m pip install SomePackage # default Python 2 py -2.7 -m pip install SomePackage # specifically Python 2.7 py -3 -m pip install SomePackage # default Python 3 py -3.4 -m pip install SomePackage # specifically Python 3.4
回答by Gus00
I had the same issue and fixed it when switching Python compiler (bottom left corner on Visual Studio Code) . Try on different versions and eventually it should work.
我在切换 Python 编译器(Visual Studio Code 的左下角)时遇到了同样的问题并修复了它。尝试不同的版本,最终它应该可以工作。
回答by IsMaTh IM
When using pip, it usually gets installed in Python 2+ so try
使用pip 时,它通常安装在 Python 2+ 中,因此请尝试
pip3 install PyPDF2