“no module named PyPDF2” error

偶尔善良 提交于 2019-12-21 03:25:09

问题


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:

import PyPDF2

I get the error:

ImportError: No module named PyPDF2

How can I fix this?


回答1:


If you use python3 maybe

apt-get install python3-pypdf2



回答2:


In my case, I was trying to import 'pyPdf2' instead of 'PyPDF2'. Observe the case.

import PyPDF2

is correct.




回答3:


I faced the same problem. But, In my case,

  • I previously installed Python3 separately from official website and was using without any issues

  • Then later I installed Anaconda package 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.

Then I opened Anaconda prompt and installed PyPDF2 there and tried to import. It worked!!

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.

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.




回答4:


I had this problem too when I tried to import PyPDF2 like this:

sudo apt-get install python-pypdf2

When running some simple script with import PyPDF2, I would get an error like this:

ImportError: No module named PyPDF2

The solution was to also install pdfmerge, like this:

pip install pdfmerge




回答5:


This is the case which I followed for python3. For python2 try with pip:

pip install PyPDF2



回答6:


How to install Python packages on Windows for various versions of Python which are simultaneously installed:

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:

py -3.7 -m pip install PyPDF2

INSTEAD OF:

pip install PyPDF2 or 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

Now, I can run python 3.7 with 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.


See more here: 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


来源:https://stackoverflow.com/questions/39241643/no-module-named-pypdf2-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!