18
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?

Progman
  • 16,827
  • 6
  • 33
  • 48
Lena.J
  • 209
  • 1
  • 2
  • 4
  • 1
    Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include your source code as a working [mcve], which can be tested by others. – Progman Nov 22 '22 at 19:22

7 Answers7

35

When I encountered this I used:

pip install chardet
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Ricky Shao
  • 369
  • 3
  • 3
13

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
ms82494
  • 131
  • 1
  • 4
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.

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
r poon
  • 633
  • 7
  • 7
1

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!

MoAly
  • 76
  • 3
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!

dfabat
  • 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 '22 at 04:25
0

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
bfontaine
  • 18,169
  • 13
  • 73
  • 107
Sebi_alo
  • 21
  • 4
-1

use follow instead.

pip install mmcv-full==1.3.17

happzy
  • 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](/help/how-to-answer). – Community Feb 02 '23 at 20:12