Cannot install PyPdf 2 module

后端 未结 3 676
别那么骄傲
别那么骄傲 2021-01-01 23:59

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 t

相关标签:
3条回答
  • 2021-01-02 00:39

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

    0 讨论(0)
  • 2021-01-02 00:41

    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?

    0 讨论(0)
  • 2021-01-02 00:50

    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 讨论(0)
提交回复
热议问题