pdfminer - ImportError: No module named pdfminer.pdfdocument

I had an error like this:

No module named 'pdfminer.pdfinterp'; 'pdfminer' is not a package

My problem was that I had named my script pdfminer.py which for the reasons that I don't know, Python took it for the original pdfminer package files and tried to compiled it.

I renamed my script to something else, deleted all the *.pyc file and __pycache__ directory and my problem was solved.


use this command worked for me and removed the error

pip install pdfminer.six

Since the package pdfminer is installed to a non-standard/non-default location, Python won't be be able to find it. In order to use it, you will need to add it to your 'pythonpath'. Three ways:

  1. At run time, put this in your script pdf2txt.py:

    import sys
    # if there are no conflicting packages in the default Python Libs =>
    sys.path.append("/usr/home/username/pdfminer")
    

    or

    import sys
    # to always use your package lib before the system's =>
    sys.path.insert(1, "/usr/home/username/pdfminer")
    

    Note: The install path specified with --home is used as the Lib for all packages which you might want to install, not just this one. You should delete that folder and re-install with -- home=/usr/home/username/myPyLibs (or any generic name) so that when you install other packages with that install path, you would only need the one path to add to your local Lib to be able to import them:

    import sys
    sys.path.insert(1, "/usr/home/username/myPyLibs")
    
  2. Add it to PYTHONPATH before executing your script:

    export PYTHONPATH="${PYTHONPATH}:/usr/home/username/myPyLibs"
    

    And then put that in your ~/.bashrc file (/usr/home/username/.bashrc) or .profile as applicable. This may not work for programs which are not executed from the console.

  3. Create a VirtualEnv and install the packages you need to that.