pip 安装faiss 不能用,使用conda安装并使用faiss成功

pip 安装faiss 安装过程没有报错,import时候必报错!!!

1.安装cpu版本faiss

pip --default-time=1000 install -i https://pypi.tuna.tsinghua.edu.cn/simple faiss

2、 报错 ModuleNotFoundError: No module named '_swigfaiss'

 File "/usr/local/lib/python3.6/dist-packages/faiss/swigfaiss.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 658, in _load_unlocked
  File "", line 571, in module_from_spec
  File "", line 922, in create_module
  File "", line 219, in _call_with_frames_removed
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests/tools_test/faiss_test.py", line 13, in 
    import faiss
  File "/usr/local/lib/python3.6/dist-packages/faiss/__init__.py", line 19, in 
    from .swigfaiss import *
  File "/usr/local/lib/python3.6/dist-packages/faiss/swigfaiss.py", line 17, in 
    _swigfaiss = swig_import_helper()
  File "/usr/local/lib/python3.6/dist-packages/faiss/swigfaiss.py", line 16, in swig_import_helper
    return importlib.import_module('_swigfaiss')
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_swigfaiss'

 

 

3、从下面网址下载安装包anaconda版本

wget https://repo.continuum.io/archive/Anaconda3-2019.10-Linux-x86_64.sh

4、开始安装:

bash Anaconda3-2019.10-Linux-x86_64.sh

之后一路 回车或者输入yes即可

  1. 配置环境变量

vim ~/.bashrc

export PATH="/home/thrc_pyj/anaconda3/bin:$PATH

source ~/.bashrc

使用 conda --version 确认是否安装成功。
创建虚拟环境,命名为faiss,python版本为3.7conda create -name faiss python=3.7
激活虚拟环境 source activate faiss
conda常用命令
source ~/.bashrc 环境变量的配置
conda list 显示那些安装好的库
conda env list 显示那些环境列表
conda create -name faiss python=3.7 创建一个名为torch1的环境,python版本配置为3.7
source activate faiss 激活faiss环境
conda deactivate 返回默认base环境
conda remove –name faiss –all 删除faiss环境

5、再次安装faiss

conda install faiss-cpu -c pytorch

如果使用gpu版本,使用

# 安装faiss的GPU 版本
conda install faiss-gpu cudatoolkit=8.0 -c pytorch # For CUDA8
conda install faiss-gpu cudatoolkit=9.0 -c pytorch # For CUDA9
conda install faiss-gpu cudatoolkit=10.0 -c pytorch # For CUDA10

 

6、 检测faiss是否成功

python

Python 3.7.4 (default, Aug 13 2019, 20:35:49)

[GCC 7.3.0] :: Anaconda, Inc. on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import faiss

>>> faiss.__version__

'1.6.3'

你可能感兴趣的:(python,python)