Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named '_swigfaiss #821

Closed
1 of 3 tasks
shashi-netra opened this issue May 8, 2019 · 13 comments
Closed
1 of 3 tasks

ImportError: No module named '_swigfaiss #821

shashi-netra opened this issue May 8, 2019 · 13 comments

Comments

@shashi-netra
Copy link

Summary

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?

Platform

Ubuntu 16 & Python3

Running on:

  • [x ] CPU
  • GPU

Interface:

  • C++
  • Python

Reproduction instructions

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'
>>> 
@beauby
Copy link
Contributor

beauby commented May 9, 2019

The loader cannot find libomp.so. Where do you have it installed?

@shashi-netra
Copy link
Author

Ok I figured it out, I needed to install openMP and did so using this:
sudo apt-get install libomp-dev

@xxllp
Copy link

xxllp commented Jul 5, 2019

how to do on centos sys ,@shashi-netra

@flynnzhao
Copy link

flynnzhao commented Sep 27, 2019

It should not be so:

pip install faiss

should do:

CPU version only

conda install faiss-cpu -c pytorch

GPU version

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

@hzitoun
Copy link

hzitoun commented Nov 26, 2019

conda install faiss-cpu -c pytorch instead of pip install faiss makes everything work

@Arjunsankarlal
Copy link

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 👍

@dvlshah
Copy link

dvlshah commented Apr 29, 2020

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

@RaviTezu
Copy link

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:

  1. Uninstall both the faiss and faiss-cpu using: pip uninstall -y faiss faiss-cpu
  2. Install faiss-cpu only: pip install faiss-cpu --no-cache

Once 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.

@YuanCao1996
Copy link

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.

@kouchong666666
Copy link

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 👍

very nice

@anewusername77
Copy link

It should not be so:

pip install faiss

should do:

CPU version only

conda install faiss-cpu -c pytorch

GPU version

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

i use

conda install faiss-gpu cudatoolkit=10.2 -c pytorch 

but still have error: ModuleNotFoundError: No module named '_swigfaiss'

@wanesta
Copy link

wanesta commented Nov 16, 2021

(tf19-py36) root@recom_algresearch_ubuntugpu73v99_syq:/data/relateRecom/gsm/ComiRec# conda install faiss-gpu cudatoolkit=11.3.1 -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

(tf19-py36) root@recom_algresearch_ubuntugpu73v99_syq:/data/relateRecom/gsm/ComiRec# python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import faiss
Traceback (most recent call last):
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/swigfaiss_gpu.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: libcudart.so.8.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 "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/__init__.py", line 21, in <module>
    from .swigfaiss_gpu import *
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/swigfaiss_gpu.py", line 17, in <module>
    _swigfaiss_gpu = swig_import_helper()
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/swigfaiss_gpu.py", line 16, in swig_import_helper
    return importlib.import_module('_swigfaiss_gpu')
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_swigfaiss_gpu'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/swigfaiss.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: libmkl_gnu_thread.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 "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/__init__.py", line 28, in <module>
    from .swigfaiss import *
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/swigfaiss.py", line 17, in <module>
    _swigfaiss = swig_import_helper()
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/site-packages/faiss/swigfaiss.py", line 16, in swig_import_helper
    return importlib.import_module('_swigfaiss')
  File "/data/relateRecom/anaconda3/envs/tf19-py36/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_swigfaiss'

@yunus-temurlenk
Copy link

python3 -m pip install faiss-cpu
or

python3 -m pip install faiss
solved my problem, needed to be carefull. also uninstall swig package:

sudo apt remove swig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests