You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M1 Air上Python3.12导入FAISS失败求助:官方安装方案无效

解决M1 MacBook Air + Python3.12下FAISS导入失败问题

针对你在M1芯片MacBook Air、Python3.12环境中安装faiss-gpu/faiss-cpu后仍无法导入的问题,以下是适配ARM架构的解决方案:

方案1:使用Conda安装适配ARM的FAISS

M1属于ARM架构,官方PyPI的faiss-cpu包可能未适配Python3.12的ARM版本,建议通过conda-forge安装:

  1. 确保你安装了支持ARM的conda(比如Miniforge3)
  2. 执行命令:
conda install -c conda-forge faiss-cpu

如果conda速度慢,可替换为mamba:

mamba install -c conda-forge faiss-cpu

方案2:从源码编译FAISS

如果不想用conda,可手动编译适配ARM的FAISS:

  1. 安装编译依赖:
brew install cmake llvm
  1. 克隆FAISS仓库:
git clone https://github.com/facebookresearch/faiss.git
cd faiss
  1. 编译CPU版本:
mkdir build && cd build
cmake -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=ON -DCMAKE_CXX_COMPILER=$(brew --prefix llvm)/bin/clang++ ..
make -j$(sysctl -n hw.ncpu)
  1. 安装Python绑定:
cd ../python
python setup.py install

方案3:替换为无需FAISS的向量存储

如果上述方案仍有问题,可改用LangChain支持的其他向量存储(如Chroma),无需编译适配:

  1. 安装Chroma:
pip install chromadb
  1. 修改代码中的向量存储部分:
    将原代码中from langchain_community.vectorstores import FAISS替换为:
from langchain_community.vectorstores import Chroma

将get_vector_store函数修改为:

def get_vector_store(text_chunks):
    embeddings = GooglePalmEmbeddings()
    vector_store = Chroma.from_texts(text_chunks, embedding=embeddings)
    return vector_store

内容的提问来源于stack exchange,提问作者Andy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 05:55:27