To fix the "Import error: cannot import name 'open_filename' from 'pdfminer.utils'" error, you can follow these steps:
pip install pdfminer.six --upgrade
from pdfminer.utils import open_filename
pip uninstall pdfminer.six
pip install pdfminer.six
As we had installed both pdfminer and pdfminer.six, we decided to keep pdfminer.six and uninstall pdfminer. To do this, we executed the following command:
pip uninstall pdfminer
This command removes the pdfminer package from our Python environment. By keeping pdfminer.six and removing pdfminer, we ensure consistency and avoid potential conflicts between the two packages.
We face a similar problem where we couldn't import the name 'open_filename' from 'pdfminer.utils' After investigating, we found that the issue was related to using Python version 3.11.x.
Our solution was to downgrade our Python environment to version 3.8.18, and this resolved the problem. By downgrading to a lower version, we ensured compatibility with the langchain cookbook and successfully imported the necessary functions from pdfminer.utils.
While upgrading to the latest Python version is generally recommended for access to new features and improvements, in this case, compatibility issues with specific libraries necessitated a downgrade.So you can also try by upgrading to the latest Python version.