huggingface / huggingface_hub

The official Python client for the Huggingface Hub.
https://huggingface.co/docs/huggingface_hub
Apache License 2.0
1.82k stars 470 forks source link

print actual error message when failing to load a submodule #2342

Closed kallewoof closed 2 weeks ago

kallewoof commented 2 weeks ago

Great confusion in #2089 due to the actual underlying error being hidden behind importlib catching. This PR prints the error to console to help the user figure out what is going wrong.

kallewoof commented 2 weeks ago
-> % python
Python 3.12.3 | packaged by Anaconda, Inc. | (main, May  6 2024, 19:46:43) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from huggingface_hub import hf_hub_download
Error importing huggingface_hub.file_download: partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import)
Error importing huggingface_hub.file_download: partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'hf_hub_download' from 'huggingface_hub' (/home/user/workspace/huggingface_hub/src/huggingface_hub/__init__.py). Did you mean: 'cached_download'?
>>> 
(ws) user@linux [13:07:49] [~/ws] 
-> % pip install -U charset-normalizer
Requirement already satisfied: charset-normalizer in /home/user/workspace/miniconda3/envs/ws/lib/python3.12/site-packages (3.3.2)
(ws) user@linux [13:09:44] [~/ws] 
-> % pip install --force-reinstall -U charset-normalizer
Collecting charset-normalizer
  Using cached charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (33 kB)
Using cached charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (141 kB)
Installing collected packages: charset-normalizer
  Attempting uninstall: charset-normalizer
    Found existing installation: charset-normalizer 3.3.2
    Uninstalling charset-normalizer-3.3.2:
      Successfully uninstalled charset-normalizer-3.3.2
Successfully installed charset-normalizer-3.3.2
(ws) user@linux [13:09:52] [~/ws] 
-> % python                                                                                                     
Python 3.12.3 | packaged by Anaconda, Inc. | (main, May  6 2024, 19:46:43) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from huggingface_hub import hf_hub_download
>>>
HuggingFaceDocBuilderDev commented 2 weeks ago

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.