huggingface_hub
huggingface_hub copied to clipboard
huggingface_hub cannot import name 'hf_hub_download' from 'huggingface_hub'
Describe the bug
I have the latest version o huggingface_hub.
In python console I can import huggingface_hub
but not its sumbodule `hf_hub_download``
Thanks for the attention.
Reproduction
❯ python
Python 3.11.7 (main, Dec 15 2023, 12:09:04) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import huggingface_hub
>>> from huggingface_hub import hf_hub_download
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'hf_hub_download' from 'huggingface_hub' (/usr/local/anaconda3/lib/python3.11/site-packages/huggingface_hub/__init__.py)
>>>
Logs
No response
System info
I can not even launch the command for this Issue "system Info" description
>>> from huggingface_hub import dump_environment_info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'dump_environment_info' from 'huggingface_hub' (/usr/local/anaconda3/lib/python3.11/site-packages/huggingface_hub/__init__.py)
>>> dump_environment_info()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'dump_environment_info' is not defined
>>>
Hi @stefanolatini, I suspect there's something wrong in your setup. Could you upgrade to a recent version?
pip install --upgrade huggingface_hub
If this doesn't work, you can uninstall + reinstall it completely:
pip uninstall huggingace_hub
pip install huggingface_hub
Both hf_hub_download
and dump_environment_info
have been around for a long time (>12 months) so you should be able to import them correctly.
still not work
still not work
I have the same issue
still not work
I have the same issue
I don't know what caused it, I just used conda to create a virtual environment
Could you tell me what precise steps you do to create the conda virtual env + install dependencies? Also could you try to create a new env, install huggingface_hub, try if it's correctly installed. If yes, continue by installing other dependencies you need and check which one cause trouble. Could you also copy-paste the output of pip freeze
? This kind of installation/package conflicts is kinda hard to investigate without a reproducible script to be honest.
I solved the issue and just needed to go down to python 3.9
I solved the issue and just needed to go down to python 3.9
It could also be that I have a problem with conda, and I use the base environment
I had the same problem. System information: Win10 Pro 22H2 Python 3.10.11
Traceback (most recent call last):
File "E:\Code\Python\myStudy\test_240531\__init__.py", line 1, in <module>
from huggingface_hub import hf_hub_download as hhdown
ImportError: cannot import name 'hf_hub_download' from 'huggingface_hub' (D:\software\Python\Python310\lib\site-packages\huggingface_hub\__init__.py)
@zunmx could you try what I explained in https://github.com/huggingface/huggingface_hub/issues/2089#issuecomment-2136834052 and let me know how it goes?
@zunmx could you try what I explained in #2089 (comment) and let me know how it goes?
I did not use the virtual environment, directly installed the python
pip package list
aiofiles==23.2.1
altgraph==0.17.4
annotated-types==0.6.0
antlr4-python3-runtime==4.9.3
anyio==4.3.0
APScheduler==3.10.4
astor==0.8.1
asttokens==2.4.1
async-timeout==4.0.3
attrdict==2.0.1
attrs==23.2.0
Babel==2.15.0
bce-python-sdk==0.9.7
bcrypt==4.1.3
beautifulsoup4==4.12.3
blinker==1.8.1
bottle==0.12.25
cachetools==5.3.3
cefpython3==66.1
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
ChatTTS==0.0.5
cheap-repr==0.5.1
ci-info==0.3.0
click==8.1.7
clr-loader==0.2.6
colorama==0.4.6
comtypes==1.4.1
configobj==5.0.8
configparser==7.0.0
contourpy==1.2.1
cryptography==42.0.6
cssselect==1.2.0
cssutils==2.10.2
cycler==0.12.1
Cython==3.0.10
decorator==5.1.1
dill==0.3.8
dnspython==2.6.1
ecdsa==0.19.0
einops==0.8.0
einx==0.2.2
email_validator==2.1.1
encodec==0.1.1
et-xmlfile==1.1.0
etelemetry==0.3.1
exceptiongroup==1.2.1
executing==2.0.1
fastapi==0.83.0
fastapi-cli==0.0.2
filelock==3.14.0
fire==0.6.0
Flask==3.0.3
flask-babel==4.0.0
fonttools==4.51.0
frontend==0.0.3
frozendict==2.4.4
fsspec==2024.3.1
future==1.0.0
gevent==24.2.1
greenlet==3.0.3
h11==0.14.0
httpcore==1.0.5
httplib2==0.22.0
httptools==0.6.1
httpx==0.27.0
huggingface-hub==0.23.2
idna==3.7
imageio==2.34.1
imgaug==0.4.0
intel-openmp==2021.4.0
ipython==8.24.0
iso8601==2.1.0
isodate==0.6.1
itsdangerous==2.2.0
jedi==0.19.1
Jinja2==3.1.3
keyboard==0.13.5
kiwisolver==1.4.5
lazy_loader==0.4
llvmlite==0.42.0
lmdb==1.4.1
looseversion==1.3.0
ltp==4.2.13
ltp-core==0.1.4
ltp-extension==0.1.13
lxml==5.2.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.8.4
matplotlib-inline==0.1.7
mdurl==0.1.2
mkl==2021.4.0
mock==2.0.0
more-itertools==10.2.0
mpmath==1.3.0
multiprocess==0.70.16
networkx==3.3
nibabel==5.2.1
nipype==1.8.6
Nuitka==2.2.3
numba==0.59.1
numpy==1.26.4
omegaconf==2.3.0
openai-whisper==20231117
opencv-contrib-python==4.6.0.66
opencv-python==4.6.0.66
opencv-python-headless==4.9.0.80
openpyxl==3.1.2
opt-einsum==3.3.0
ordered-set==4.1.0
orjson==3.10.3
outcome==1.3.0.post0
packaging==24.0
paddleocr==2.7.3
paddlepaddle-gpu==2.6.1
pandas==2.2.2
parso==0.8.4
passlib==1.7.4
pbr==6.0.0
pdf2docx==0.5.8
pdfkit==1.0.0
pefile==2023.2.7
pillow==10.3.0
plum-dispatch==1.7.4
premailer==3.10.0
prompt_toolkit==3.0.45
protobuf==3.20.2
prov==2.0.0
proxy_tools==0.1.0
psutil==5.9.8
pure-eval==0.2.2
pyasm==1.1.5
pyasn1==0.6.0
pyclipper==1.3.0.post5
pycparser==2.22
pycryptodome==3.20.0
pydantic==1.10.15
pydantic_core==2.18.2
pydot==2.0.0
PyExecJS==1.5.1
Pygments==2.18.0
pyinstaller==6.7.0
pyinstaller-hooks-contrib==2024.6
PyMuPDF==1.24.2
PyMuPDFb==1.24.1
PyMySQL==1.1.0
pyparsing==3.1.2
PyQt6==6.4.2
pyqt6-plugins==6.4.2.2.3
PyQt6-Qt6==6.4.3
PyQt6-sip==13.6.0
pyqt6-tools==6.4.2.3.3
PySocks==1.7.1
python-dateutil==2.9.0.post0
python-docx==1.1.2
python-dotenv==1.0.1
python-jose==3.3.0
python-lzo==1.15
python-multipart==0.0.9
pythonnet==3.0.3
pythonping==1.1.4
pytz==2024.1
PyVirtualDisplay==3.0
pywebview==5.1
pywin32==306
pywin32-ctypes==0.2.2
pyxnat==1.6.2
PyYAML==6.0.1
qt6-applications==6.4.3.2.3
qt6-tools==6.4.3.1.3
rapidfuzz==3.9.0
rarfile==4.2
rdflib==7.0.0
readmdict==0.1.1
redis==5.0.4
regex==2024.4.28
requests==2.13.0
rich==13.7.1
rsa==4.9
safetensors==0.4.3
scapy==2.5.0
scikit-image==0.23.2
scipy==1.13.0
selenium==4.20.0
serial==0.0.97
shapely==2.0.4
shellingham==1.5.4
simplejson==3.19.2
six==1.16.0
sniffio==1.3.1
snoop==0.4.3
sortedcontainers==2.4.0
soupsieve==2.5
spire==0.4.2
Spire.Doc==12.4.0
SQLAlchemy==2.0.29
stack-data==0.6.3
starlette==0.19.1
sympy==1.12
tbb==2021.12.0
termcolor==2.4.0
tifffile==2024.5.3
tiktoken==0.6.0
tkwebview2==3.5.0
tokenizers==0.19.1
torch==2.1.2
torchaudio==2.1.2
tornado==6.4
tqdm==4.66.4
traitlets==5.14.3
traits==6.3.2
transformers==4.41.2
trio==0.25.0
trio-websocket==0.11.1
ttkbootstrap==1.10.1
typer==0.12.3
typing_extensions==4.11.0
tzdata==2024.1
tzlocal==5.2
ujson==5.9.0
urllib3==2.2.1
uvicorn==0.29.0
vector-quantize-pytorch==1.14.24
visualdl==2.5.3
voc==0.1.6
Vocabulary==1.0.4
vocos==0.1.0
watchfiles==0.21.0
wcwidth==0.2.13
websocket==0.2.1
websocket-client==1.8.0
websockets==12.0
Werkzeug==3.0.2
whisper==1.1.10
win32wifi==0.1.0
windnd==1.0.7
wsproto==1.2.0
xlrd==2.0.1
xmltodict==0.13.0
zhdate==0.1
zope.event==5.0
zope.interface==6.3
zstandard==0.22.0
@zunmx What if you use a virtualenv? Would be good to check if you have the same issue when starting from a clean state.
I have the same question. I made sure I had the latest version of huggingface_hub installed in my conda environment.
(ChatTTS) PS D:\PyCharmProject\ChatTTS> pip install --upgrade huggingface_hub
Requirement already satisfied: huggingface_hub in d:\anaconda\envs\chattts\lib\site-packages (0.23.2)
Requirement already satisfied: filelock in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (3.13.1)
Requirement already satisfied: packaging>=20.9 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (24.0)
Requirement already satisfied: pyyaml>=5.1 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (6.0.1)
Requirement already satisfied: requests in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (2.32.2)
Requirement already satisfied: tqdm>=4.42.1 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (4.66.4)
Requirement already satisfied: typing-extensions>=3.7.4.3 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (4.11.0)
Requirement already satisfied: colorama in d:\anaconda\envs\chattts\lib\site-packages (from tqdm>=4.42.1->huggingface_hub) (0.4.6)
Requirement already satisfied: charset-normalizer<4,>=2 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (2.2.1)
Requirement already satisfied: certifi>=2017.4.17 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (2024.2.2)
(ChatTTS) PS D:\PyCharmProject\ChatTTS> pip install --upgrade huggingface_hub
Requirement already satisfied: huggingface_hub in d:\anaconda\envs\chattts\lib\site-packages (0.23.2)
Requirement already satisfied: filelock in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (3.13.1)
Requirement already satisfied: packaging>=20.9 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (24.0)
Requirement already satisfied: pyyaml>=5.1 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (6.0.1)
Requirement already satisfied: requests in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (2.32.2)
Requirement already satisfied: tqdm>=4.42.1 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (4.66.4)
Requirement already satisfied: typing-extensions>=3.7.4.3 in d:\anaconda\envs\chattts\lib\site-packages (from huggingface_hub) (4.11.0)
Requirement already satisfied: colorama in d:\anaconda\envs\chattts\lib\site-packages (from tqdm>=4.42.1->huggingface_hub) (0.4.6)
Requirement already satisfied: charset-normalizer<4,>=2 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (2.2.1)
Requirement already satisfied: certifi>=2017.4.17 in d:\anaconda\envs\chattts\lib\site-packages (from requests->huggingface_hub) (2024.2.2)
(ChatTTS) PS D:\PyCharmProject\ChatTTS> python
Python 3.9.19 (main, May 6 2024, 20:12:36) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from huggingface_hub import hf_hub_download
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'hf_hub_download' from 'huggingface_hub' (D:\Anaconda\envs\ChatTTS\lib\site-packages\huggingface_hub\__init__.py)
@DrNaki can you retry installing inside a clean virtualenv -i.e. starting from scratch- and see if it still produces the error? If yes, I'd be interested to get the reproducible steps you used.
To start a new env, run
# Will create a new env inside `./.env/`
python -m venv .env/
and then activate it with
# linux/macos
source ./.env/bin/activate
# windows
venv\Scripts\activate
At least using python's virtualenv. If you use conda to create it that's fine as well (just let me know how you do it exactly when providing the reproducible steps).
Try rebooting your virtual env. Might be helpful.
I'm also having the same issue.
I use huggingface-hub 0.23.4, python 3.9 and conda 24.4.0.
What I tried:
- upgrade huggingface-hub
- reinstall huggingface-hub
- clean the pip cache and reinstall huggingface-hub
- list the functions of huggingface-hub and ensure that
hf_hub_download
is there. - reboost the virtual environment
None of them works:(
Can someone help?
I'm also having the same issue.
I use huggingface-hub 0.23.4, python 3.9 and conda 24.4.0.
What I tried:
- upgrade huggingface-hub
- reinstall huggingface-hub
- clean the pip cache and reinstall huggingface-hub
- list the functions of huggingface-hub and ensure that
hf_hub_download
is there.- reboost the virtual environment
None of them works:(
Can someone help?
I just solved that problem, though I don't know how it works. I create a new conda environment, and reinstall torch and all other needed packages.
I have the same issue in one of my conda environments. The environment is running python 3.12. I have another conda env on python 3.11 that is working fine. Both are on huggingface_hub==0.21.1. I tried upgrading the broken one to latest to no avail.
Creating a new conda environment on python 3.12 and installing huggingface_hub worked fine. No issues. So the 3.11 vs 3.12 python version diff is not the cause.
Digging deeper, the implementation is raising an exception when trying to do
submod = importlib.import_module(submod_path)
with a
partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import)
I made a PR #2342 which catches and displays errors inside the __getattr__
method, which should help people find the actual underlying cause.
Thanks for digging into it and opening this PR @kallewoof! I'll merge it soon which should help a lot future users. Nice finding!
conda install chardet
I think this issue is fixed by #2342 and can be closed. If people still have this problem they should open a new issue.
Yes agree, thanks for following-up on this @kallewoof! The PR you mentioned should be released today :)