Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Import No Module Named error

I pip installed pdfminer: https://pypi.python.org/pypi/pdfminer/20140328 on ubuntu 13.10 and that successfully installed into /usr/local/lib/python2.7/dist-packages/pdfminer

when I try to run the example code:

from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfpage import PDFTextExtractionNotAllowed
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfdevice import PDFDevice


if __name__=='__main__':
    # Open a PDF file.
    fp = open('MyPDF.pdf', 'rb')

I keep getting

ImportError: No module named pdfparser

I have verified that pdfparser exists and there is a __init__.py file in the pdfminer folder. I have tried recreating the __init__.py file. I have also tried runing chmod -R 777 pdfminer but that doesn't fix it either.

I have run env but there is no PYTHONPATH there is that a problem? I have also tried installing PDFMiner into a virtualenv but that doesn't work either. I noticed that PDFMiner requires root permissions to install is that the problem?

what am I doing wrong?

like image 267
KillerSnail Avatar asked Jul 14 '26 14:07

KillerSnail


2 Answers

Have you tried

from pdfminer import pdfparser

or

import pdfminer.pdfparser

?

like image 176
Misrab Avatar answered Jul 16 '26 05:07

Misrab


Are you running the code from a file called pdfminer.py?

This was causing the error in my case. Python was trying to import the module from the file of the same name.

like image 26
zadrozny Avatar answered Jul 16 '26 04:07

zadrozny