huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
130.19k stars 25.87k forks source link

Import Error : cannot import name 'create_repo' from 'huggingface_hub' #15062

Closed santanumitra22 closed 2 years ago

santanumitra22 commented 2 years ago

Working with BERT Text Classification,i found this error

import torch from tqdm.notebook import tqdm

from transformers import BertTokenizer

from torch.utils.data import TensorDataset

from transformers import BertForSequenceClassification

ImportError: cannot import name 'create_repo' from 'huggingface_hub' (C:\ProgramData\Anaconda3\lib\site-packages\huggingface_hub__init__.py)

How to solve this?

frankhart2018 commented 2 years ago

@santanumitra22 Which transformers version are you using?

santanumitra22 commented 2 years ago

Version: 4.15.0 @frankhart2018

frankhart2018 commented 2 years ago

And is you huggingface_hub version 0.2.1?

santanumitra22 commented 2 years ago

no, huggingface_hub 0.0.8

frankhart2018 commented 2 years ago

That's probably the issue, can you try upgrading to 0.2.1, its working fine for me when I am using 0.2.1

Yansera commented 2 years ago

Same issue here, my transformers version is 4.15.0., and the huggingface_hub version is 0.2.1. However, it does not work.

rsm5909 commented 2 years ago

Same issue here, my transformers version is 4.15.0., and the huggingface_hub version is 0.2.1. However, it does not work.

I was able to correct this by restarting the python kernel (working in Jupyter Lab) after logging in to the CLI

Yansera commented 2 years ago

Error fixed, thanks! :)

rsmith49 commented 2 years ago

This happened for me from a fresh install of

conda install transformers

on an Ubuntu Deep Learning AMI. Is there a huggingface_hub dependency that should be updated?

DevavratSinghBisht commented 2 years ago

That's probably the issue, can you try upgrading to 0.2.1, its working fine for me when I am using 0.2.1

Faced same issue, updating to 0.2.1 helped, thanks!

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

GeorgiosEtsias commented 2 years ago

In my case downgrading python 3.8 to 3.7 is what solved the problem.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

iknoorjobs commented 2 years ago

Same issue here, my transformers version is 4.15.0., and the huggingface_hub version is 0.2.1 both updated to latest version. However, it does not work. I'm still getting the following import error

Import Error : cannot import name 'create_repo' from 'huggingface_hub'

LysandreJik commented 2 years ago

The latest huggingface_hub version is v0.5.1; how did you identify that v0.2.1 was the latest? This is definitely an error with the wrong version being installed.

iknoorjobs commented 2 years ago

Hi @LysandreJik, thanks! Yes, I tried conda update huggingface_hub and conda update transformers but it doesn't work. I finally solved this by doing a fresh installation of both of these in a new environment.

LysandreJik commented 2 years ago

Glad you got it to work! Very weird that conda refused to update your packages, let me know if it happens again!

stefanhgm commented 2 years ago

I experienced the same problem today:

> conda create -n test_env python=3.7
> conda activate test_env
> conda install huggingface_hub
> conda list | grep hugging
huggingface_hub           0.2.1              pyhd3eb1b0_0

Could maybe the python version be the problem? When using conda-forge I get the most recent version:

> conda create -n test_env python=3.7
> conda activate test_env
> conda install -c conda-forge huggingface_hub
> conda list | grep hugging
huggingface_hub           0.5.1              pyhd8ed1ab_0    conda-forge

Also, installing subsequent dependencies not from conda-forge actually downgraded huggingface_hub to 0.1.7, so people that run into the same problem might try to install their remaining packages from conda-forge as well an keep an eye on conda whether it attempts to downgrade huggingface_hub.

roysubhankar commented 2 years ago

For me conda update huggingface_hub and conda update transformers worked nicely.

cgr71ii commented 1 year ago

Here's my two cents: I had installed transformers 4.10.3 and huggingface-hub 0.4.0 and was throwing

ImportError: cannot import name 'RepositoryNotFoundError' from 'huggingface_hub.utils'

Then I ran

pip install --upgrade huggingface-hub

After that, huggingface-hub was updated to version 0.9.1, didn't modify any other version of my environment, and solved the problem.

brando90 commented 1 year ago

in case this doesn't work for you upgrade pip e.g.

/Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin/python -m pip install --upgrade pip
pip install --upgrade huggingface-hub
brando90 commented 1 year ago
huggingface-hub                                   0.10.0
transformers                                      4.13.0

my issue happens and above is true

brando90 commented 1 year ago

what about upgrading all 3?

/Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin/python -m pip install --upgrade pip
pip install --upgrade transformers
pip install --upgrade huggingface-hub
pip install --upgrade datasets

ok failed but now the error is:

Traceback (most recent call last):
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 11, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/transformers/__init__.py", line 30, in <module>
    from . import dependency_versions_check
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/transformers/dependency_versions_check.py", line 36, in <module>
    from .utils import is_tokenizers_available
ImportError: cannot import name 'is_tokenizers_available' from 'transformers.utils' (/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/transformers/utils/__init__.py)
brando90 commented 1 year ago
/Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin/python -m pip install --upgrade pip
pip install --upgrade tokenizers

upgraded correctly trom 0.12.1 to 0.13.0 still fails.

(meta_learning) ❯ pip list 
Package                                           Version    Editable project location
------------------------------------------------- ---------- ------------------------------------------------------------------------------
absl-py                                           1.0.0
aiohttp                                           3.8.1
aiosignal                                         1.2.0
antlr4-python3-runtime                            4.8
argcomplete                                       2.0.0
async-timeout                                     4.0.1
attrs                                             21.4.0
automl-meta-learning                              0.1.0      /Users/brandomiranda/automl-meta-learning/automl-proj-src
bcj-cffi                                          0.5.1
boto                                              2.49.0
Bottleneck                                        1.3.4
Brotli                                            1.0.9
brotlicffi                                        1.0.9.2
brotlipy                                          0.7.0
cachetools                                        4.2.4
certifi                                           2022.9.14
cffi                                              1.15.1
charset-normalizer                                2.0.9
cherry-rl                                         0.1.4
click                                             8.0.3
cloudpickle                                       2.0.0
colorama                                          0.4.4
configparser                                      5.2.0
conllu                                            4.4.1
crcmod                                            1.7
cryptography                                      37.0.1
cycler                                            0.11.0
Cython                                            0.29.25
dataclasses                                       0.6
datasets                                          2.5.1
dill                                              0.3.4
diversity-for-predictive-success-of-meta-learning 0.0.1      /Users/brandomiranda/diversity-for-predictive-success-of-meta-learning/div_src
docker-pycreds                                    0.4.0
editdistance                                      0.6.0
et-xmlfile                                        1.1.0
fairseq                                           0.10.0
fastcluster                                       1.2.4
fasteners                                         0.17.3
filelock                                          3.6.0
fonttools                                         4.28.3
frozenlist                                        1.2.0
fsspec                                            2022.7.1
gcs-oauth2-boto-plugin                            3.0
gitdb                                             4.0.9
GitPython                                         3.1.24
google-apitools                                   0.5.32
google-auth                                       2.3.3
google-auth-oauthlib                              0.4.6
google-reauth                                     0.1.1
grpcio                                            1.42.0
gsutil                                            5.6
gym                                               0.21.0
h5py                                              3.6.0
higher                                            0.2.1
httplib2                                          0.20.4
huggingface-hub                                   0.10.0
hydra-core                                        1.1.1
idna                                              3.3
importlib-metadata                                4.11.3
joblib                                            1.1.0
kiwisolver                                        1.3.2
lark-parser                                       0.12.0
learn2learn                                       0.1.7
lxml                                              4.8.0
Markdown                                          3.3.6
matplotlib                                        3.5.1
mkl-fft                                           1.3.1
mkl-random                                        1.2.2
mkl-service                                       2.4.0
monotonic                                         1.6
multidict                                         5.2.0
multiprocess                                      0.70.12.2
multivolumefile                                   0.2.3
munkres                                           1.1.4
networkx                                          2.6.3
numexpr                                           2.8.1
numpy                                             1.21.5
oauth2client                                      4.1.3
oauthlib                                          3.1.1
omegaconf                                         2.1.1
openpyxl                                          3.0.10
ordered-set                                       4.0.2
packaging                                         21.3
pandas                                            1.4.2
pathtools                                         0.1.2
Pillow                                            9.0.1
pip                                               22.2.2
plotly                                            5.4.0
portalocker                                       2.3.2
progressbar2                                      3.55.0
promise                                           2.3
protobuf                                          3.19.1
psutil                                            5.8.0
py7zr                                             0.16.1
pyarrow                                           9.0.0
pyasn1                                            0.4.8
pyasn1-modules                                    0.2.8
pycparser                                         2.21
pycryptodomex                                     3.15.0
pyOpenSSL                                         22.0.0
pyparsing                                         3.0.6
pyppmd                                            0.16.1
PySocks                                           1.7.1
python-dateutil                                   2.8.2
python-utils                                      2.5.6
pytz                                              2021.3
pyu2f                                             0.1.5
PyYAML                                            6.0
pyzstd                                            0.14.4
qpth                                              0.0.15
regex                                             2021.11.10
requests                                          2.28.1
requests-oauthlib                                 1.3.0
responses                                         0.18.0
retry-decorator                                   1.1.1
rsa                                               4.7.2
sacrebleu                                         2.0.0
sacremoses                                        0.0.46
scikit-learn                                      1.0.1
scipy                                             1.7.3
seaborn                                           0.11.2
sentry-sdk                                        1.5.1
setproctitle                                      1.2.2
setuptools                                        58.0.4
shortuuid                                         1.0.8
six                                               1.16.0
sklearn                                           0.0
smmap                                             5.0.0
subprocess32                                      3.5.4
tabulate                                          0.8.9
tenacity                                          8.0.1
tensorboard                                       2.7.0
tensorboard-data-server                           0.6.1
tensorboard-plugin-wit                            1.8.0
termcolor                                         1.1.0
texttable                                         1.6.4
threadpoolctl                                     3.0.0
tokenizers                                        0.12.1
torch                                             1.9.1
torchaudio                                        0.9.1
torchmeta                                         1.8.0
torchtext                                         0.10.1
torchvision                                       0.10.1
tornado                                           6.1
tqdm                                              4.62.3
transformers                                      4.22.2
typing_extensions                                 4.3.0
ultimate-anatome                                  0.1.1      /Users/brandomiranda/ultimate-anatome
ultimate-aws-cv-task2vec                          0.0.1      /Users/brandomiranda/ultimate-aws-cv-task2vec
ultimate-utils                                    0.6.1      /Users/brandomiranda/ultimate-utils/ultimate-utils-proj-src
urllib3                                           1.26.11
wandb                                             0.13.3
Werkzeug                                          2.0.2
wheel                                             0.37.0
xxhash                                            2.0.2
yarl                                              1.8.1
yaspin                                            2.1.0
zipp                                              3.8.0
brando90 commented 1 year ago

did:

pip install pytorch-transformers

didn't work same eroor about tokenizer.

brando90 commented 1 year ago

trying:

/Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin/python -m pip install --upgrade pip
pip install --upgrade torch
pip install --upgrade torchvision
pip install --upgrade torchtext
pip install --upgrade torchaudio

# pip install --upgrade torchmeta
pip uninstall torchmeta

still fails with:

Traceback (most recent call last):
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 11, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/transformers/__init__.py", line 30, in <module>
    from . import dependency_versions_check
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/transformers/dependency_versions_check.py", line 36, in <module>
    from .utils import is_tokenizers_available
ImportError: cannot import name 'is_tokenizers_available' from 'transformers.utils' (/Users/brandomiranda/opt/anaconda3/envs/meta_learning/lib/python3.9/site-packages/transformers/utils/__init__.py)

SO post: https://stackoverflow.com/questions/73939929/how-to-resolve-the-hugging-face-error-importerror-cannot-import-name-is-tokeni

conan1024hao commented 1 year ago

I was able to correct this by restarting the python kernel (working in Jupyter Lab) after logging in to the CLI

solved by @rsm5909 's, thanks!

damlitos commented 1 year ago

restarting Jupyter notebook has solved the problem

XitraQ commented 11 months ago

omg, this tooooook too long none of the above worked, not sure if i tried it all, but i tried

This is what worked for me: open cmd in venv/scripts write:

pip uninstall tqdm
pip install tqdm

or get it upgraded, since this one was old for me! alternative commands

py -m pip uninstall tqdm
py -m pip install tqdm

OR python -m

The issue is that one of your tqdm's are not same version you have to go to huggingface_hub/utils probably too and do the same

and maybe even go into init.py and edit with VSCode or something the top code # from . import tqdm as _tqdm # _tqdm is the module just add the # or remove the whole line

I might have missed something, because I tried so much Hope it helps anyone else

BitCalSaul commented 8 months ago

My previous issue is "cannot import name 'get_full_repo_name' from 'huggingface_hub'", and I use the command "conda install chardet" to fix it.

hughesadam87 commented 3 months ago

I'm getting this issue now - april 2024. Clean virtual env pip install transformers and huggingface_Hub

lixikun commented 1 month ago

conda install chardet

use this conda install chardet and pip install --upgrade requests

jingyiz86 commented 1 month ago

conda install chardet

use this conda install chardet and pip install --upgrade requests

this works for me:)

nathan-tsien commented 3 weeks ago

conda install chardet

use this conda install chardet and pip install --upgrade requests

yeah, it works.

drug311 commented 3 weeks ago

conda install chardet

use this conda install chardet and pip install --upgrade requests

it works.