Linux 环境可使用如下命令解决:

sudo apt-get install libopenblas-dev
sudo apt-get install libomp-dev

以下为windows10 下的情况
【此部分可以略过,直接看下面的解决方法】
问题:在安装Faiss包后,import faiss 报下错。

ImportError: DLL load failed while importing _swigfaiss: 找不到指定的模块。

我进行了以下三种尝试,均未解决问题。【你可以先尝试下面的解法】

  • 使用anaconda安装此包,会有莫名其妙的冲突,并安装失败。命令:conda install faiss-cpu -c pytorch
  • 使用pip命令安装,报错。命令:pip install faiss-cpu
  • 下载faiss本地包,使用pip命令进行安装,报错。本地包下载地址:https://pypi.tuna.tsinghua.edu.cn/simple/faiss-cpu/ (下载whl包,并使用pip命令安装。)

最终解决方法:
1、卸载所有已安装的包.

pip uninstall faiss-cpu
conda uninstall faiss

2、更换anaconda国内源【没更换源时,使用第3步的命令,会报错,在我尝试更改后,解决问题】

1、添加清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
设置搜索时显示通道地址(下同)
conda config --set show_channel_urls yes
2、添加中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes

3、使用anaconda安装faiss【安装等待时间较长

conda install faiss-cpu -c pytorch

安装成功,问题解决。


若还不行,你可以尝试升级anaconda的所有包,再使用第3步卸载重装,来试一试

conda update --all

tips:你可以在官方issue中找到一些提示:https://github.com/facebookresearch/faiss/issues

Logo

鸿蒙生态一站式服务平台。

更多推荐