Reputation: 27
I've just started using Python with Spyder at work, which means I'm far more restricted than normal as I have no access to the command line.
I'm trying to access the PyPDF2 library, which I have downloaded as a ZIP file, and then pointed to this file with the PYTHONPATH manager. I still can't access it:
from PyPDF2 import PdfFileMerger, PdfFileReader
gets: "ImportError: No module named 'PyPDF2'"
All the walk throughs I've seen of using PYTHONPATH involve using the command line. Can anyone help with how to do this without this access? Sorry am relatively new to this and really stuck!
Thanks
Upvotes: 1
Views: 4113
Reputation: 102
I don't know anything about Spyder, but in Anaconda there is a way to install packages from the Anaconda Navigator. If Spyder doesn't have this feature, you can do the following:
At the top of your script, before any other imports, add the following code, where PYPDFPATH is the location of the PyPDFPath folder
import sys
sys.path.append('PYPDFPATH')
In your script, try importing PyPDF2 as you did in your question. If you've done everything right, you should have no problems.
The sys.path variable is a list that contains all of the folders that Python should look for modules. If you add a folder to this list with modules you'd like to import in it before you import them, Python will look for those modules in this folder in addition to the default folders it looks for modules in.
Note that if you downloaded the PyPDF2 zip from GitHub, your PyPDF2 directory needs to contain the PyPDF2 directory from inside the zip instead of the entire repository.
I hope this helps!
Upvotes: 2