Faiss: no module named _swigfaiss

Created on 10 Feb 2018  ·  9Comments  ·  Source: facebookresearch/faiss

I recently build FAISS using (FAISS is in /usr/local/)
sudo cmake CMakeList.txt
sudo make

(When I ran
sudo make py
It gave me error : make: * No rule to make target 'py'. Stop.)

Now I try to ran : python -c "import faiss"
Then it gave me this error
Traceback (most recent call last):
File "", line 1, in
File "faiss.py", line 28, in
from swigfaiss import *
File "/usr/local/faiss/python/swigfaiss.py", line 28, in
_swigfaiss = swig_import_helper()
File "/usr/local/faiss/python/swigfaiss.py", line 20, in swig_import_helper
import _swigfaiss
ImportError: No module named _swigfaiss

Even module swigfaiss was made available only after I added PYTHONPATH=./python/ That contain the .py file of swigfaiss.py

Any help is appreciated.

install

Most helpful comment

@da230896 My apologies if I wasn't clear enough. Yes, "makefile.inc" includes the necessary flags to build the project using the main Makefile, which does have the py target. The latter imports "makefile.inc", which must be in the base of the project. In Linux, you can start off by doing something like this:

cp example_makefiles/makefile.inc.Linux ./makefile.inc

Then perform the necessary tweaks to "makefile.inc". Personally, I changed line 118 to use Python 3, among a few other things. With that done, running make py should suffice.

All 9 comments

Hi
Make sure that the _swigfaiss.so file is in the PYTHONPATH

Hi,
But the problem I am facing is that even after compiling I do not have any file named '_swigfaiss.py' or '_swigfaiss.so' in the whole faiss build folder.(ls -r | grep -E '_swigfaiss.py' )or( ls -r | grep -E '_swigfaiss.so') both returns empty list.

I did some searching and found out that it has some reference in swigfaiss_wrap.cxx at line number 3078.

Is there anything missing in my build procedure ?

make py works with the regular makefiles, not with the ones generated with cmake. The cmake does not support the python interface AFAIK.

Hi,
So what I can make out from your comment is I have to write a custom make file!? I am novice and at this moment I would have loved to install a library by simple commands.

Also I tried to compile swigfaiss_wrap.cxx into _swigfaiss.so However it gave me some undefined symbols , have a look :

ImportError: ./_swigfaiss.so: undefined symbol: _ZN5faiss15VectorTransform5trainElPKf

@da230896 Not really, the Makefile is already available. You just need to set up a "makefile.inc" file for your system (examples are in "example_makefiles/") and run make py. The instructions are over here.

I am also facing same issue, i did following steps
1) Cloned FAISS
2) updated makefile.inc with anaconda python path and installed necessary dependencies like libopenblas-dev python-numpy python-dev
3) make (After this step i am not finding any _swigfaiss.so files anywhere)
4) make py (Gave following error)
$ make py
g++ -I. -fPIC -m64 -Wall -g -O3 -msse4 -mpopcnt -fopenmp -Wno-sign-compare -std=c++11 -fopenmp -g -fPIC -fopenmp -I~/anaconda2/envs/faissenv/include/python2.7/ -I~/anaconda2/envs/faissenv/lib/python2.7/site-packages/numpy/core/include -shared \
-o python/_swigfaiss.so python/swigfaiss_wrap.cxx libfaiss.a /usr/lib/libopenblas.so.0
python/swigfaiss_wrap.cxx:154:21: fatal error: Python.h: No such file or directory
compilation terminated.
Makefile:84: recipe for target 'python/_swigfaiss.so' failed
make: * [python/_swigfaiss.so] Error 1
I am able to run cpp implementation, but only this python wrapper is failing, let me know what i am setting wrong. As _swigfaiss.so is not generated, what went wrong while doing make?

@Enet4 I can only see flags set in the makefile.inc.linux . But no rule to make target 'py' . I have set all the required flags .

I know I have to add 'py' target on my own ,that is why it is not there ,but I have no experience in writing a makefile . I know I can learn from google but it can be accelerated if you can post me your makefile.inc here so that I can have some contextual knowledge as well.

Also I think there is a pull request regarding python integration , would suggest to speedily merge it .

@Mahanteshambi Python.h is in /usr/include/python2.7/ in my linux box.

@da230896 My apologies if I wasn't clear enough. Yes, "makefile.inc" includes the necessary flags to build the project using the main Makefile, which does have the py target. The latter imports "makefile.inc", which must be in the base of the project. In Linux, you can start off by doing something like this:

cp example_makefiles/makefile.inc.Linux ./makefile.inc

Then perform the necessary tweaks to "makefile.inc". Personally, I changed line 118 to use Python 3, among a few other things. With that done, running make py should suffice.

Hi @Enet4
Okay so I have installed faiss . You can close the issue .Kudos to you all guys.
My mistake was running 'sudo cmake CMakeList.txt' which removed default Makefile with its own generated Makefile and as @mdouze said there was no support for 'make py' in it and that is where I got confused.

However When I ran ./tests/demo_ivfpq_indexing
I got a segmentation fault :
[0.000 s] Generating 100000 vectors in 128D for training
[0.991 s] Training the index
Training level-1 quantizer
Training level-1 quantizer on 100000 vectors in 128D
Segmentation fault (core dumped)

Which do not look good ! :( (Some MKL error i suppose)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ljferrer picture Ljferrer  ·  3Comments

xxllp picture xxllp  ·  3Comments

lukedeo picture lukedeo  ·  3Comments

Tony-Hou picture Tony-Hou  ·  3Comments

hashyong picture hashyong  ·  3Comments