transformers: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS'
System Info
macbook pro m2 with anaconda, python 3.9
I’m running transformers on an m1 mac and am getting the following error when I import
from transformers import OwlViTProcessor, OwlViTForObjectDetection
File ~/opt/anaconda3/envs/nd1/lib/python3.9/site-packages/transformers/init.py:26 23 from typing import TYPE_CHECKING 25 # Check the dependencies satisfy the minimal versions required. —> 26 from . import dependency_versions_check 27 from .utils import ( 28 OptionalDependencyNotAvailable, 29 _LazyModule, (…) 42 logging, 43 ) 46 logger = logging.get_logger(name) # pylint: disable=invalid-name
File ~/opt/anaconda3/envs/nd1/lib/python3.9/site-packages/transformers/dependency_versions_check.py:36 33 if pkg in deps: 34 if pkg == “tokenizers”: 35 # must be loaded here, or else tqdm check may fail —> 36 from .utils import is_tokenizers_available … —> 10 from charset_normalizer.md import mess_ratio 11 from charset_normalizer.models import CharsetMatches, CharsetMatch 12 from warnings import warn
AttributeError: partially initialized module ‘charset_normalizer’ has no attribute ‘md__mypyc’ (most likely due to a circular import)
Who can help?
No response
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examples
folder (such as GLUE/SQuAD, …) - My own task or dataset (give details below)
Reproduction
Install transformers on a macbook m2
from transformers import OwlViTProcessor, OwlViTForObjectDetection
Expected behavior
it should import but instaed it gives the above error message
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (1 by maintainers)
System Info
macbook air m2 with anaconda, python 3.9
I got a similar bug 🐛
ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant'
When I encountered this I used:
python -m pip install charset-normalizer==2.1.0
solves the issue
Actually I was getting the same error when importing OpenAI but that was solved by upgrading the package
pip install --upgrade chardet
And that worked!
Encountered the same error message when importing transformers. Installing chardet solved the issue.
Output for transformers-cli env
transformers
version: 4.28.0.dev0It’s working for me. You are the best.
I got the above error and did
python -m pip install charset-normalizer==2.1.0
. This gave me another error which went away after doingpip install chardet
.The error after 2.1.0 was as below but it was solved. I’m using M2 MAX and the packages below.
ImportError: cannot import name 'KO_NAMES' from 'charset_normalizer.constant' (/opt/anaconda3/envs/mlenv/lib/python3.8/site-packages/charset_normalizer/constant.py)
Package Version
anyio 3.6.2 appnope 0.1.2 argon2-cffi 21.3.0 argon2-cffi-bindings 21.2.0 arrow 1.2.3 asttokens 2.0.5 attrs 22.2.0 backcall 0.2.0 beautifulsoup4 4.11.2 bleach 6.0.0 brotlipy 0.7.0 certifi 2022.12.7 cffi 1.15.1 chardet 5.1.0 charset-normalizer 2.1.0 click 8.1.3 comm 0.1.2 contourpy 1.0.7 cryptography 39.0.1 cycler 0.11.0 debugpy 1.6.6 decorator 5.1.1 defusedxml 0.7.1 executing 0.8.3 fastjsonschema 2.16.2 filelock 3.9.0 flit_core 3.6.0 fonttools 4.39.0 fqdn 1.5.1 future 0.18.2 gmpy2 2.1.2 huggingface-hub 0.12.1 idna 3.4 importlib-metadata 6.0.0 importlib-resources 5.12.0 ipykernel 6.21.2 ipython 8.10.0 ipython-genutils 0.2.0 ipywidgets 8.0.4 isoduration 20.11.0 jedi 0.18.1 Jinja2 3.1.2 joblib 1.2.0 jsonpointer 2.3 jsonschema 4.17.3 jupyter 1.0.0 jupyter_client 8.0.3 jupyter-console 6.6.1 jupyter_core 5.2.0 jupyter-events 0.6.3 jupyter_server 2.3.0 jupyter_server_terminals 0.4.4 jupyterlab-pygments 0.2.2 jupyterlab-widgets 3.0.5 kiwisolver 1.4.4 MarkupSafe 2.1.2 matplotlib 3.7.1 matplotlib-inline 0.1.6 mistune 2.0.5 mkl-fft 1.3.1 mkl-random 1.2.2 mkl-service 2.4.0 mpmath 1.3.0 nbclassic 0.5.2 nbclient 0.7.2 nbconvert 7.2.9 nbformat 5.7.3 nest-asyncio 1.5.6 networkx 3.0 nltk 3.8.1 notebook 6.5.2 notebook_shim 0.2.2 numpy 1.23.5 packaging 23.0 pandas 1.5.3 pandocfilters 1.5.0 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 Pillow 9.4.0 pip 22.3.1 pkgutil_resolve_name 1.3.10 platformdirs 3.0.0 portalocker 2.7.0 prometheus-client 0.16.0 prompt-toolkit 3.0.36 psutil 5.9.4 ptyprocess 0.7.0 pure-eval 0.2.2 pycparser 2.21 Pygments 2.11.2 pyOpenSSL 23.0.0 pyparsing 3.0.9 pyrsistent 0.19.3 PySocks 1.7.1 python-dateutil 2.8.2 python-json-logger 2.0.7 pytorch-crf 0.7.2 pytz 2023.2 PyYAML 6.0 pyzmq 25.0.0 qtconsole 5.4.0 QtPy 2.3.0 regex 2022.10.31 requests 2.28.2 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 scikit-learn 1.2.2 scikit-plot 0.3.7 scipy 1.10.1 seaborn 0.12.2 Send2Trash 1.8.0 sentence-transformers 2.2.2 sentencepiece 0.1.97 setuptools 65.6.3 six 1.16.0 sklearn 0.0.post1 sniffio 1.3.0 soupsieve 2.4 stack-data 0.2.0 sympy 1.11.1 terminado 0.17.1 threadpoolctl 3.1.0 tinycss2 1.2.1 tokenizers 0.12.1 torch 2.0.0 torchaudio 2.0.0 torchdata 0.6.0 torchtext 0.13.0 torchvision 0.15.0 tornado 6.2 tqdm 4.64.1 traitlets 5.7.1 transformers 4.27.4 typing_extensions 4.4.0 uri-template 1.2.0 urllib3 1.26.15 wcwidth 0.2.5 webcolors 1.12 webencodings 0.5.1 websocket-client 1.5.1 wheel 0.38.4 widgetsnbextension 4.0.5 zipp 3.14.0
I am currently having this issue with one anaconda environment and not another. This is very confusing.
You can try opening an issue at charset_normalizer and point out that their 3.1.0 release seems broken on MacOS (but 2.1.0 works apparently, from the comment above).
From your traceback, the simple line
import charset_normalizer
should fail in your environment (it doesn’t in mine, but I’m not on MacOS).Yes, we can try to have it solve in requests first indeed. It’s if that takes too much time or is not deemed important we should fix it in hf hub.
@ani0075saha Could you try the two lines given by Wauplin and do step 2 and 3?