13

Trying to install PyPdf2 module, I downloaded the zip and unzipped it, I executed python setup.py build and python setup.py install, but it seems that it has not been installed , when I try to import it from a python script, it returns an ImportError:

import pyPdf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pyPdf

Any help please.

I'm using python 2.7 under windows XP.

geogeek
  • 1,155
  • 3
  • 22
  • 40
  • there's no errors during module installation, i tried to import it from python command line, i tried every possible name for the module (upper case), but without a result :( – geogeek Oct 08 '12 at 11:26
  • yeah the module PDF2 directory is located in C:\Python27\Lib\site-packages as you guessed , and i have installed modules before without problems – geogeek Oct 08 '12 at 12:05
  • @Evert i've made an update , thanks – geogeek Oct 08 '12 at 13:01

3 Answers3

27

It appears the README file for PyPDF2 is incorrect. It suggests that

import pyPdf

should work, but it doesn't. This new module is imported as

import PyPDF2

(as suggested by the document structure on github, and after verifying myself).

For convenience, when e.g. working with older code, you can of course do

import PyPDF2 as pyPdf
0

The PyPDF installer for Windows works well for me. (Win7-64) http://pybrary.net/pyPdf/

anh_ng8
  • 1,020
  • 10
  • 16
  • You'd probably want to use PyPDF2 though. Could you perhaps check whether merging files work? – PascalVKooten Mar 30 '13 at 20:51
  • i have tried merging files, it works well, but i have had a bug when merging PDFs containing strange unicode charachters, the error described here http://stackoverflow.com/questions/12781994/pypdf-merge-error , i have not found a real solution , so i used itextsharp for c# – geogeek Mar 30 '13 at 21:05
  • @Dualinity: Merging files works like charm for me. I haven't tried with Unicode chars as the comment above. – anh_ng8 Apr 26 '13 at 22:02
0

Figured out so far what the issue is. Need to check if further commands of PyPDF2 works. The import PyPDF2 looks for PyPDF2 folder in the base location of python. In my case it is C:\Python27\site-packages\PyPDF2.

When virtualenv is activated, pip install PyPDF2 does not create the above folder. Hence the error. I manually copied the PyPDF2 folder and PyPDF2-1.26.0.dist-info folder from my virtualenv environment into the base folder above and the error stopped. Just in case, I created new virtualenv environment and installed PyPDF2 with and without virtualenv activated and the error is gone.

My folder structure:

  • C:\Python27\site-packages\PyPDF2
  • C:\Python27\site-packages\PyPDF2-1.26.0.dist-info

  • C:\Python27\venv2\Lib\site-packages\PyPDF2

  • C:\Python27\venv2\Lib\site-packages\PyPDF2-1.26.0.dist-info

Python script is very simple to test the import:

#import sys
import PyPDF2

#print(sys.path)
print('hello')

I troubleshooted the above using the stackoverflow response to check syspath How does python find a module file if the import statement only contains the filename?

Athul Nath
  • 2,446
  • 1
  • 13
  • 27