Faiss: Please add step-by-step instructions for how to compile the Python wrapper

Created on 2 Mar 2017  路  4Comments  路  Source: facebookresearch/faiss

It would be very helpful if you could add the actual commands that are necessary to compile the Python wrappers to the readme.

Right now the instructions assume that I know what I am doing :)

Step 2: Compiling the Python interface

The Python interface is provided via SWIG (Simple Wrapper and
Interface Generator) and an additional level of manual wrappers (in faiss.py).

SWIG generates two wrapper files: a Python file (swigfaiss.py) and a
C++ file that must be compiled to a dynamic library (_swigfaiss.so).

The C++ compilation to the dynamic library requires to set:

  • SHAREDFLAGS: system-specific flags to generate a dynamic library

  • PYTHONCFLAGS: include flags for Python

See the example makefile.inc's on how to set the flags.

I think I have figured out step 1 by myself:
swig -c++ -python swigfaiss.swig

which generates several swigfaiss_* .py and .c files. So I assume the final step that I am missing is to make the dynamic library. It would be very helpful if you could list the actual line that needs to be run.

Most helpful comment

Ok, I updated the doc, you can just run

make py

Thanks for pointing this out

All 4 comments

Hmmm... Let me clarify this:

  • the makefile will make the python wrapper for you
  • and even this is not necessary because the pre-generated wrapper code is in the repo

The makefile only makes the faiss.py file for me. When I run

python -c "import faiss"

I get

Failed to load GPU Faiss: No module named swigfaiss_gpu
Faiss falling back to CPU-only.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "faiss.py", line 28, in <module>
    from swigfaiss import *
  File "swigfaiss.py", line 28, in <module>
    _swigfaiss = swig_import_helper()
  File "swigfaiss.py", line 20, in swig_import_helper
    import _swigfaiss
ImportError: No module named _swigfaiss

Ok, I updated the doc, you can just run

make py

Thanks for pointing this out

Perfect - that fixed it. Test import works now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ljferrer picture Ljferrer  路  3Comments

linghuang picture linghuang  路  3Comments

zoe-cheung picture zoe-cheung  路  3Comments

brunodoamaral picture brunodoamaral  路  3Comments

wwmmqq picture wwmmqq  路  3Comments