Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' #7631

Closed
dbl001 opened this issue May 11, 2024 · 3 comments

Comments

@dbl001
Copy link

dbl001 commented May 11, 2024

Describe the bug

I'm on MacOS Sonoma in a Conda virtual enviornment. When I try to import wandb I get an exception.
If I force a pip reinstallation of charset_normalizer the issues is resolved ... until I run $ conda update --all in the virtual environment.

% ipython
Python 3.10.13 (main, Sep 11 2023, 08:21:04) [Clang 14.0.6 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.20.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import wandb
In [1]: import wandb
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/requests/compat.py:11
     10 try:
---> 11     import chardet
     12 except ImportError:

ModuleNotFoundError: No module named 'chardet'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 import wandb

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/wandb/__init__.py:27
     24 # This needs to be early as other modules call it.
     25 from wandb.errors.term import termsetup, termlog, termerror, termwarn
---> 27 from wandb import sdk as wandb_sdk
     29 import wandb
     31 wandb.wandb_lib = wandb_sdk.lib  # type: ignore

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/wandb/sdk/__init__.py:24
      1 """module sdk."""
      3 __all__ = (
      4     "Config",
      5     "Settings",
   (...)
     21     "helper",
     22 )
---> 24 from . import wandb_helper as helper
     25 from .artifacts.artifact import Artifact
     26 from .wandb_alerts import AlertLevel

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/wandb/sdk/wandb_helper.py:6
      2 import types
      4 from wandb.errors import UsageError
----> 6 from .lib import config_util
      9 def parse_config(params, exclude=None, include=None):
     10     if exclude and include:

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/wandb/sdk/lib/config_util.py:10
      8 import wandb
      9 from wandb.errors import Error
---> 10 from wandb.util import load_yaml
     12 from . import filesystem
     14 logger = logging.getLogger("wandb")

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/wandb/util.py:53
     34 from types import ModuleType
     35 from typing import (
     36     IO,
     37     TYPE_CHECKING,
   (...)
     50     Union,
     51 )
---> 53 import requests
     54 import yaml
     56 import wandb

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/requests/__init__.py:45
     41 import warnings
     43 import urllib3
---> 45 from .exceptions import RequestsDependencyWarning
     47 try:
     48     from charset_normalizer import __version__ as charset_normalizer_version

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/requests/exceptions.py:9
      1 """
      2 requests.exceptions
      3 ~~~~~~~~~~~~~~~~~~~
      4 
      5 This module contains the set of Requests' exceptions.
      6 """
      7 from urllib3.exceptions import HTTPError as BaseHTTPError
----> 9 from .compat import JSONDecodeError as CompatJSONDecodeError
     12 class RequestException(IOError):
     13     """There was an ambiguous exception that occurred while handling your
     14     request.
     15     """

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/requests/compat.py:13
     11     import chardet
     12 except ImportError:
---> 13     import charset_normalizer as chardet
     15 import sys
     17 # -------
     18 # Pythons
     19 # -------
     20 
     21 # Syntax sugar.

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/charset_normalizer/__init__.py:23
      1 """
      2 Charset-Normalizer
      3 ~~~~~~~~~~~~~~
   (...)
     21 :license: MIT, see LICENSE for more details.
     22 """
---> 23 from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
     24 from charset_normalizer.legacy import detect
     25 from charset_normalizer.version import __version__, VERSION

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/charset_normalizer/api.py:10
      7     PathLike = Union[str, 'os.PathLike[str]']  # type: ignore
      9 from charset_normalizer.constant import TOO_SMALL_SEQUENCE, TOO_BIG_SEQUENCE, IANA_SUPPORTED
---> 10 from charset_normalizer.md import mess_ratio
     11 from charset_normalizer.models import CharsetMatches, CharsetMatch
     12 from warnings import warn

File ~/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/charset_normalizer/md.py:5
      2 from typing import Optional, List
      4 from charset_normalizer.constant import UNICODE_SECONDARY_RANGE_KEYWORD
----> 5 from charset_normalizer.utils import is_punctuation, is_symbol, unicode_range, is_accentuated, is_latin, \
      6     remove_accent, is_separator, is_cjk, is_case_variable, is_hangul, is_katakana, is_hiragana, is_ascii, is_thai
      9 class MessDetectorPlugin:
     10     """
     11     Base abstract class used for mess detection plugins.
     12     All detectors MUST extend and implement given methods.
     13     """

ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (/Users/davidlaxer/anaconda3/envs/AI-Feynman/lib/python3.10/site-packages/charset_normalizer/constant.py)

$ conda update --all tries to install

The following NEW packages will be INSTALLED:

  charset-normalizer pkgs/main/noarch::charset-normalizer-2.0.4-pyhd3eb1b0_0 


Proceed ([y]/n)? n

Which breaks the wandb package.

Additional Files

No response

Environment

WandB version:
Version: 0.17.0

OS:
MacOS Sonomia 14.1.1

Python version:
Python 3.10.13

Versions of relevant libraries:
% pip show charset-normalizer

Name: charset-normalizer
Version: 3.3.2

% conda list charset-normalizer

packages in environment at /Users/davidlaxer/anaconda3/envs/AI-Feynman:

Name Version Build Channel

charset-normalizer 3.3.2 pypi_0 pypi

Additional Context

No response

@JoanaMarieL
Copy link

Hi @dbl001 , happy to help. This issue seems to be related to dependency conflicts when updating your environment.

  1. First step would be to create new environment
conda create --name new_env python=3.10
conda activate new_env
pip install wandb

Then run simple wandb script

import wandb
wandb.init()
wandb.finish()
  1. If you are installing other packages then you might need to pin some versions in your environment and exclude them from updates
  • Freeze the versions of these dependencies to prevent them from being updated. Add the following lines to your requirements.txt in environment. charset_normalizer==2.0.4 chardet==4.0.0
  • Exclude specific packages from the update.

conda update --all --ignore-installed=charset_normalizer,chardet

Let us know if you have further questions.

@dbl001
Copy link
Author

dbl001 commented May 21, 2024

Thanks! Pinning to charset_normalizer==2.0.4 resolved this.

 % conda list charset-normalizer
# packages in environment at /Users/davidlaxer/anaconda3/envs/AI-Feynman:
#
# Name                    Version                   Build  Channel
charset-normalizer        2.0.4              pyhd3eb1b0_0  

@dbl001 dbl001 closed this as completed May 21, 2024
@JoanaMarieL
Copy link

Glad to hear that @dbl001 , we'll mark this as resolved and feel free to reach us out again for any concern. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants