mirror of
https://github.com/facebookresearch/faiss.git
synced 2025-06-03 21:54:02 +08:00
Python install (#469)
* add a working setup.py * Rename setup.py to python/setup.py * Fix paths in setup.py * Use relative imports for python3 compatibility. * Add python/install Makefile target. * Fix test target in Makefile.
This commit is contained in:
parent
6e40d6689f
commit
21fbc56dfd
5
Makefile
5
Makefile
@ -64,7 +64,8 @@ depend:
|
||||
|
||||
test: libfaiss.a py
|
||||
make -C tests run
|
||||
PYTHONPATH=./python $(PYTHON) -m unittest discover tests/ -v
|
||||
PYTHONPATH=./python/build/`ls python/build | grep lib` \
|
||||
$(PYTHON) -m unittest discover tests/ -v
|
||||
|
||||
|
||||
#############################
|
||||
@ -85,7 +86,7 @@ misc/test_blas: misc/test_blas.cpp
|
||||
# Python
|
||||
|
||||
py:
|
||||
$(MAKE) -C python
|
||||
$(MAKE) -C python build
|
||||
|
||||
|
||||
.PHONY: all clean default demos install installdirs py test uninstall
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
HEADERS = $(wildcard ../*.h)
|
||||
|
||||
all: cpu
|
||||
all: cpu build
|
||||
|
||||
#############################
|
||||
# CPU
|
||||
@ -43,9 +43,15 @@ _swigfaiss_gpu.so: swigfaiss_gpu_wrap.o ../gpu/libgpufaiss.a ../libfaiss.a
|
||||
$(CXX) $(SHAREDFLAGS) $(NVCCLDFLAGS) -o $@ $^ $(NVCCLIBS)
|
||||
|
||||
|
||||
build: cpu
|
||||
$(PYTHON) setup.py build
|
||||
|
||||
install: build
|
||||
$(PYTHON) setup.py install
|
||||
|
||||
clean:
|
||||
rm -f swigfaiss_wrap.cpp swigfaiss_gpu_wrap.cpp
|
||||
rm -f swigfaiss.py swigfaiss_gpu.py
|
||||
rm -f _swigfaiss.so _swigfaiss_gpu.so
|
||||
|
||||
.PHONY: all clean cpu gpu
|
||||
.PHONY: all build clean cpu gpu install
|
||||
|
@ -18,14 +18,14 @@ import pdb
|
||||
# we import * so that the symbol X can be accessed as faiss.X
|
||||
|
||||
try:
|
||||
from swigfaiss_gpu import *
|
||||
from .swigfaiss_gpu import *
|
||||
except ImportError as e:
|
||||
|
||||
if 'No module named' not in e.args[0]:
|
||||
# swigfaiss_gpu is there but failed to load: Warn user about it.
|
||||
sys.stderr.write("Failed to load GPU Faiss: %s\n" % e.args[0])
|
||||
sys.stderr.write("Faiss falling back to CPU-only.\n")
|
||||
from swigfaiss import *
|
||||
from .swigfaiss import *
|
||||
|
||||
|
||||
##################################################################
|
||||
|
51
python/setup.py
Normal file
51
python/setup.py
Normal file
@ -0,0 +1,51 @@
|
||||
from __future__ import print_function
|
||||
from setuptools import setup, find_packages
|
||||
import os
|
||||
import shutil
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
check_fpath = os.path.join("_swigfaiss.so")
|
||||
if not os.path.exists(check_fpath):
|
||||
print("Could not find {}".format(check_fpath))
|
||||
print("Have you run `make` and `make py` "
|
||||
"(and optionally `cd gpu && make && make py && cd ..`)?")
|
||||
|
||||
# make the faiss python package dir
|
||||
shutil.rmtree("faiss", ignore_errors=True)
|
||||
os.mkdir("faiss")
|
||||
shutil.copyfile("faiss.py", "faiss/__init__.py")
|
||||
shutil.copyfile("swigfaiss.py", "faiss/swigfaiss.py")
|
||||
shutil.copyfile("_swigfaiss.so", "faiss/_swigfaiss.so")
|
||||
try:
|
||||
shutil.copyfile("_swigfaiss_gpu.so", "faiss/_swigfaiss_gpu.so")
|
||||
shutil.copyfile("swigfaiss_gpu.py", "faiss/swigfaiss_gpu.py")
|
||||
except:
|
||||
pass
|
||||
|
||||
long_description="""
|
||||
Faiss is a library for efficient similarity search and clustering of dense
|
||||
vectors. It contains algorithms that search in sets of vectors of any size,
|
||||
up to ones that possibly do not fit in RAM. It also contains supporting
|
||||
code for evaluation and parameter tuning. Faiss is written in C++ with
|
||||
complete wrappers for Python/numpy. Some of the most useful algorithms
|
||||
are implemented on the GPU. It is developed by Facebook AI Research.
|
||||
"""
|
||||
setup(
|
||||
name='faiss',
|
||||
version='0.1',
|
||||
description='A library for efficient similarity search and clustering of dense vectors',
|
||||
long_description=long_description,
|
||||
url='https://github.com/facebookresearch/faiss',
|
||||
author='Matthijs Douze, Jeff Johnson, Herve Jegou',
|
||||
author_email='matthijs@fb.com',
|
||||
license='BSD',
|
||||
keywords='search nearest neighbors',
|
||||
|
||||
install_requires=['numpy'],
|
||||
packages=['faiss'],
|
||||
package_data={
|
||||
'faiss': ['*.so'],
|
||||
},
|
||||
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user