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

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

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

kallewoof
Copy link
Contributor

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
Copy link
Contributor Author

kallewoof commented Jun 17, 2024

-> % 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
>>>

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really nice finding @kallewoof, thanks a lot! We've already had some similar issues and I personally didn't know some import errors were hidden. Your PR will definitely save some headaches 🎉

@Wauplin Wauplin merged commit bc20262 into huggingface:main Jun 17, 2024
14 checks passed
@HuggingFaceDocBuilderDev

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.

@kallewoof kallewoof deleted the 202406-better-error-handling branch June 17, 2024 07:34
MoritzLaurer pushed a commit to MoritzLaurer/huggingface_hub that referenced this pull request Jul 3, 2024
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

Successfully merging this pull request may close these issues.

None yet

3 participants