Installed faiss using pip3 on Ubuntu 16 (cpu)
I am unable to import faiss into python3 and it results in the following error
ImportError: No module named '_swigfaiss'
See error log below, I have installed (and re-installed!) libomp but no luck.
What could possibly be wrong?
Ubuntu 16 & Python3
Running on:
Interface:
import faiss```
<!-- Please provide specific and comprehensive instructions to reproduce the
described behavior. -->
```Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import faiss
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/faiss/swigfaiss.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: libomp.so: 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 "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/faiss/__init__.py", line 19, in <module>
from .swigfaiss import *
File "/usr/local/lib/python3.5/dist-packages/faiss/swigfaiss.py", line 17, in <module>
_swigfaiss = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/faiss/swigfaiss.py", line 16, in swig_import_helper
return importlib.import_module('_swigfaiss')
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_swigfaiss'
>>>
The loader cannot find libomp.so. Where do you have it installed?
Ok I figured it out, I needed to install openMP and did so using this:
sudo apt-get install libomp-dev
how to do on centos sys ,@shashi-netra
pip install faiss
conda install faiss-cpu -c pytorch
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
link: https://github.com/facebookresearch/faiss/blob/master/INSTALL.md
conda install faiss-cpu -c pytorch instead of pip install faiss makes everything work
For those who are working with pip and not conda, if you have installed it with,
pip install faiss
uninstall it. And then install faiss with,
pip install faiss-cpu --no-cache
This worked for me 👍
Just install three things in the following order and your problem Is solved
pip3 install faiss
sudo apt-get install libopenblas-dev
sudo apt-get install libomp-dev
Thank you @Arjunsankarlal.
I am on Mac and I had to remove both the faiss and faiss-cpu packages before installing faiss-cpu again.
Mac users:
faiss and faiss-cpu using: pip uninstall -y faiss faiss-cpufaiss-cpu only: pip install faiss-cpu --no-cacheOnce installed you may see the below error:
ImportError: dlopen(/Users/ravitezu/.virtualenvs/myproject/lib/python3.6/site-packages/faiss/_swigfaiss.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /Users/ravitezu/.virtualenvs/myproject/lib/python3.6/site-packages/faiss/_swigfaiss.cpython-36m-darwin.so
Reason: image not found
You can fix the above error by installing the libomp package using: brew install libomp.
Hope this helps.
For those who are working with pip and not conda, if you have installed it with,
pip install faiss
uninstall it. And then install faiss with,
pip install faiss-cpu --no-cache
This worked for me 👍
Thanks a lot! it's really helpful.
Most helpful comment
For those who are working with pip and not conda, if you have installed it with,
uninstall it. And then install faiss with,
This worked for me 👍