使用chromadb时遇AttributeError:hnswlib.Index无file_handle_count属性
解决Chromadb中AttributeError: 'hnswlib.Index'无'file_handle_count'属性的问题
错误详情
运行Chromadb时触发以下错误:
c:\Users\satya\AppData\Local\Programs\Python\Python39\lib\site-packages\chromadb\config.py in instance(self, type) hnswlib_count = hnswlib.Index.file_handle_count hnswlib_count = cast(int, hnswlib_count) AttributeError: type object 'hnswlib.Index' has no attribute 'file_handle_count'
当前环境版本
- Python 3.9
- hnswlib 0.7.0
- Chromadb 0.4.5
解决方案
问题根源是版本冲突:Chromadb 0.4.5依赖的是chroma-hnswlib(官方适配的分支版本),但你同时安装了官方原版hnswlib,导致代码调用了错误的库文件。
执行以下步骤修复:
- 卸载官方原版hnswlib:
pip uninstall -y hnswlib
- 确保Chromadb依赖的
chroma-hnswlib已正确安装,若缺失则手动安装:
pip install chroma-hnswlib
- 重启Python环境后重新运行代码。
也可以直接指定兼容版本一次性安装,彻底避免冲突:
pip install chromadb==0.4.5 chroma-hnswlib==0.7.3
内容的提问来源于stack exchange,提问作者Satya
相关产品推荐
相关产品推荐

