Odd error needing chardet with wandb?

I got this error:

import wandb

...

Traceback (most recent call last):
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/requests/compat.py", line 11, in <module>
    import chardet
ModuleNotFoundError: No module named 'chardet'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/afs/cs.stanford.edu/u/brando9/ultimate-utils/ultimate-utils-proj-src/uutils/__init__.py", line 52, in <module>
    from uutils.logging_uu.wandb_logging.common import setup_wandb
  File "/afs/cs.stanford.edu/u/brando9/ultimate-utils/ultimate-utils-proj-src/uutils/logging_uu/wandb_logging/common.py", line 8, in <module>
    import wandb
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/wandb/__init__.py", line 26, in <module>
    from wandb import sdk as wandb_sdk
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/wandb/sdk/__init__.py", line 3, in <module>
    from . import wandb_helper as helper  # noqa: F401
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/wandb/sdk/wandb_helper.py", line 6, in <module>
    from .lib import config_util
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/wandb/sdk/lib/config_util.py", line 10, in <module>
    from wandb.util import load_yaml
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/wandb/util.py", line 49, in <module>
    import requests
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/requests/__init__.py", line 45, in <module>
    from .exceptions import RequestsDependencyWarning
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/requests/exceptions.py", line 9, in <module>
    from .compat import JSONDecodeError as CompatJSONDecodeError
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/requests/compat.py", line 13, in <module>
    import charset_normalizer as chardet
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/charset_normalizer/__init__.py", line 23, in <module>
    from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/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' (/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/charset_normalizer/constant.py)
(data_quality) brando9~ $ pip install chardet

Collecting chardet
  Downloading chardet-5.1.0-py3-none-any.whl (199 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 199.1/199.1 kB 7.7 MB/s eta 0:00:00
Installing collected packages: chardet
Successfully installed chardet-5.1.0

why? seems odd. Thought this fixed it it seems:

pip install --upgrade pip
pip install chardet  # might be needed if wandb acts weird

idk why this is needed but this seems to work:

pip install --upgrade pip
pip install wandb --upgrade
if ! pip show chardet > /dev/null; then
    pip install chardet
fi
if ! pip show cchardet > /dev/null; then
    pip install cchardet
fi
python -c "import uutils; uutils.torch_uu.gpu_test()"

shouldn’t be happening in the first place…

Hello @brando !

This looks to be an issue with importing the requests package (which is in turn importing chardet incorrectly). As seen by the following lines:

File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/wandb/util.py", line 49, in <module>
    import requests
File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/requests/__init__.py", line 45, in <module>
    from .exceptions import RequestsDependencyWarning
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/requests/exceptions.py", line 9, in <module>
    from .compat import JSONDecodeError as CompatJSONDecodeError
  File "/lfs/ampere1/0/brando9/miniconda/envs/data_quality/lib/python3.10/site-packages/requests/compat.py", line 13, in <module>
    import charset_normalizer as chardet

I did look into the Stack Overflow discussion that you provided and it seems like the issue seems to be a conflict between pip and conda (which you were able to fix gladly).

Hi Brando, since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.