Import error : cannot import name 'open_filename' from 'pdfminer.utils'

April 2024 ยท 1 minute read

On importing pdfminer.high_level, I am getting an error cannot import name open_filename from pdfminer.utils.

I tried following steps:

  • pip3 install pdfminer.six
  • import pdfminer
  • import pdfminer.high_level
  • (and encountered error on this line)

    ImportError Traceback (most recent call last) <ipython-input-6-772e4980255d> in <module> ----> 1 import pdfminer.high_level ~\anaconda3\lib\site-packages\pdfminer\high_level.py in <module> 12 from .pdfinterp import PDFResourceManager, PDFPageInterpreter 13 from .pdfpage import PDFPage ---> 14 from .utils import open_filename 15 16 ImportError: cannot import name 'open_filename' from 'pdfminer.utils' 
    1

    3 Answers

    Hi I had the same issue.

    I had installed both pdfminer and pdfminer.six. Please keep pdfminer.six and uninstall pdfminer with:

    pip uninstall pdfminer 

    I faced a similar problem: cannot import name 'open_filename' from 'pdfminer.utils' when using the langchain cookbook. Problem was python v.3.11x. I downgraded my env to 3.8.18 and it worked.

    1

    I had an older version of pdfminer.six. This is the commit that introduced the open_filename method. Make sure your pdfminer.six version is greater than '20200402'.

    ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobW9xaWWGcn6OoqSpp6Kpeqa%2B0aipZpuRo7uwwIyipKmnoql6r63MnmSoqJWjeqe1y56lmqWVYrOzu8xmp52enZ67pr6MrquipKM%3D

    ncG1vNJzZmikpqK3b63MrGpnnJmctrWty6ianpmeqL2ir8SsZZynnWS2rrzOq6tmnaKnvLN5wpqlp6ekYrauvM6rq2amkaKybrvPnqVmnpmhsq%2BtzJ5kn6qfonqxsMWmoKedomLCtbXLrGWhrJ2h