pip安装后找不到Huggingface模块的错误
我尝试使用 pip 来安装Hugging Face模块,方式如下:
!pip install huggingface_hub -q
!conda install -c huggingface huggingface_hub
然而,当我尝试导入该模块时,会抛出一个 ModuleNotFound 错误:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [8], in <cell line: 7>()
2 # Source - https://stackoverflow.com/a/74127613
3 # Posted by Kirill Fedyanin, modified by community. See post 'Timeline' for change history
4 # Retrieved 2026-05-27, License - CC BY-SA 4.0
5 get_ipython().system('conda install -c huggingface huggingface_hub')
----> 7 from huggingface_hub import snapshot_download
8 snapshot_download(
9 repo_id="fishaudio/s2-pro",
10 local_dir="/content/fish-speech/checkpoints/s2-pro"
11 )
ModuleNotFoundError: No module named 'huggingface_hub'
如何导入 huggingface_hub 模块?
解决方案
如果你在使用Jupyter或 Colab,问题在于 !pip 可能会在与你的内核正在使用的Python环境不同的环境中安装该包。相反,运行:
import sys
!{sys.executable} -m pip install huggingface_hub -q
这确保了该包被安装在你笔记本正在使用的确切Python环境中。安装后,重启内核 并再次尝试导入。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。