21
Traceback (most recent call last):
  File "g:\mydrive\ \pdftotext_pdfminer.py", line 3, in <module>
    from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
  File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\pdfinterp.py", line 7, in <module> 
    from .cmapdb import CMap
  File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\encodingdb.py", line 7, in <module>
    from .psparser import PSLiteral
  File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\psparser.py", line 22, in <module>
    from .utils import choplist
  File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\utils.py", line 31, in <module>
    import charset_normalizer  # For str encoding detection
  File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\__init__.py", line 23, in <module>
    from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
  File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\api.py", line 10, in <module>
    from charset_normalizer.md import mess_ratio
  File "charset_normalizer\md.py", line 5, in <module>
ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\constant.py)

This error happens whenever I'm using pdfminer. I also installed pdfminer-six

My code worked just fine until two days ago. It started to happen today when I tried to just run it again without any adjustment in the file

I'm assuming maybe it's the pdfminer's problem but there's no update about the module...

(I'm running this on my conda env)

Does anyone know what this error means? and how to fix it?

1
  • 1
    Welcome to Stack Overflow. Please take the tour to learn how Stack Overflow works and read How to Ask on how to improve the quality of your question. Then edit your question to include your source code as a working minimal reproducible example, which can be tested by others.
    – Progman
    Nov 22, 2022 at 19:22

7 Answers 7

37

When I encountered this I used:

pip install chardet
17

I had the same issue, albeit with aiohttp, not pdfminer. Installing chardet instead of my existing (conda) installation of charset-normalizer resolved this error, but created other problems for me. My final solution was to remove chardet and install the current version of charset-normalizer (presently 3.1.0, not 3.0.1). This can be done with

conda install -c conda-forge charset-normalizer
5

In my case i have a conda environment, somehow i have a charset-normalizer installed somehow via the venv creation of: 2.0.4

pip list shows 2.04 conda list shows 3.01

so i remove the charset version 2.04 using:

pip uninstall charset-normalizer

then as the above solution, i reinstall using conda:

conda install -c conda-forge charset-normalizer

Rule of thumb: also use conda packages whenever available - use pip only if nothing available in the conda repository.

2

In my case, I got the same error after installing transformers (4.29.2) on Python 3.9. The problem turns out to be compitablity issue between chardet (5.1.0) and charset-normalizer (3.1.0).

I solved the issue by uninstalling both of them, and reinstalling same chardet but with older version of charset-normalizer.

pip uninstall chardet 
pip uninstall charset-normalizer
pip install chardet 
pip install charset-normalizer==2.1.0

I tried on a fresh env with conda, and got exactly same results!

1

Make sure to install the correct version of all packages. In conda env this worked for me:

  1. pip uninstall pytorch (until pytorch is not found)
  2. conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
  3. pip install cudatoolkit
  4. pip install chardet
1
  • always use conda as first priority then pip as top up
    – r poon
    Apr 26 at 9:58
0

there. I faced the same problem when trying to use the pdfplumber package today (2022-11-24) from a script I have long used with no problem. I don't know why this error is happening but found one of the solutions in this link helpful: How to fix AttributeError: partially initialized module?

Briefly, I removed my entire virtual environment using the command conda env remove --name ds (being ds the name of my environment). Then, I created a new one and installed every package I needed again through conda or pip. It is working perfectly now. Hope it works for you as well.

Out of curiosity, I have installed Tensorflow last week. Maybe it interfered with pdfplumber somehow (not sure). Have you installed any new package since the last time you used pdfminer? Best of luck!

1
  • Thank you for your comment! I made it work installing pdfminer.six instead of pdfminer after creating a new Anaconda env. hope this method works to people goes thrrough the same issue !
    – Lena.J
    Nov 29, 2022 at 4:25
-1

use follow instead.

pip install mmcv-full==1.3.17

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Feb 2 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.