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?
In my case, I was trying to import 'pyPdf2' instead of 'PyPDF2'. Observe the case.
import PyPDF2
is correct.
如果你使用 python3 也许
apt-get install python3-pypdf2
This is the case which I followed for python3. For python2 try with pip:
pip install PyPDF2
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.
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
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 # on Windows
python3.7 -m pip install PyPDF2 # on Mac and Linux
INSTEAD OF the more generic:
pip install PyPDF2
or pip3 install PyPDF2
And to upgrade pip , be very specific in your python version, like this :
py -3.7 -m pip install --upgrade pip # on Windows
python3.7 -m pip install --upgrade pip # on Mac and Linux
INSTEAD OF the more generic:
py -3 -m pip install --upgrade pip # on Windows
python3 -m pip install --upgrade pip # on Mac and Linux
Now, I can run python 3.7 with py -3.7
on Windows, or with python3.7
on Linux, and since I did py -3.7 -m pip install PyPDF2
on Windows, or python3.7 -m pip install PyPDF2
on Linux or Mac, 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
on Windows or python3.5 on Linux
, oddly enough, since apparently that was my "default Python3 version" which the more generic pip3 install PyPDF2
command must have installed the PyPDF2
module into. 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, with the 3.5 version being the "default" Python3 install location.
... work with multiple versions of Python installed in parallel?
On Linux, Mac OS X, and other POSIX systems, use the versioned Python commands in combination with the
-m
switch to run the appropriate copy ofpip
:python2 -m pip install SomePackage # default Python 2 python2.7 -m pip install SomePackage # specifically Python 2.7 python3 -m pip install SomePackage # default Python 3 python3.4 -m pip install SomePackage # specifically Python 3.4
Appropriately versioned
pip
commands may also be available.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
使用pip时,它通常安装在 Python 2+ 中,因此请尝试
pip3 install PyPDF2
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.
Im following a UDEMY course here . Im using Anaconda prompt and jupyter notebook.
I encountered the same issue as OP. What I did to have the library working:
anaconda prompt
control c
to stop the running instance conda activate ***your_env_here***
pip install PyPDF2
jupyter notebook
import PyPDF2
Hope this works for you.
I encountered the same issue today while doing Udemy course. try the following:
Hope it works for you too.
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.