Python 安装hnswlib出错解决办法
1.安装hnswlib出错
要使用hnswlib包来进行最邻近算法的运算,用pip方式安装hnswlib出现错误!
pip install hnswlib
2.解决办法
参考了网上其他的解决办法,方法如下:
2.1下载hnswlib包
电脑安装过git后,可以直接从cmd命令后下载hnswlib相关的包!
git clone https://github.com/nmslib/hnswlib.git
2.2下载pybind11包
pybind11 是一个轻量级的只包含一组头文件的 C++ 库,可以在 Python 中使用 C++ 类型。主要用于创建已有 C++ 代码的 Python 封装版本。其目的和语法类似于 Boost.Python 库。
pybind官网作用说明:
pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code. Its goals and syntax are similar to the excellent Boost.Python library by David Abrahams: to minimize boilerplate code in traditional extension modules by inferring type information using compile-time introspection.
The main issue with Boost.Python—and the reason for creating such a similar project—is Boost. Boost is an enormously large and complex suite of utility libraries that works with almost every C++ compiler in existence. This compatibility has its cost: arcane template tricks and workarounds are necessary to support the oldest and buggiest of compiler specimens. Now that C++11-compatible compilers are widely available, this heavy machinery has become an excessively large and unnecessary dependency.
Think of this library as a tiny self-contained version of Boost.Python with everything stripped away that isn’t relevant for binding generation. Without comments, the core header files only require ~4K lines of code and depend on Python (2.7 or 3.5+, or PyPy) and the C++ standard library. This compact implementation was possible thanks to some of the new C++11 language features (specifically: tuples, lambda functions and variadic templates). Since its creation, this library has grown beyond Boost.Python in many ways, leading to dramatically simpler binding code in many common situations.
Tutorial and reference documentation is provided at pybind11.readthedocs.io. A PDF version of the manual is available here. And the source code is always available at github.com/pybind/pybind11.
使用pip的方式安装pybind11
pip install pybind11
2.3在hnswlib包进行操作
首先,进入hnswli包目录下
然后,进入cmd命令行该目录路径,执行以下命令
python setup.py install
结果:
解决办法:
1.从此路径C:\Program Files (x86)\Windows Kits\8.1\bin\x86 目录下复制 rc.exe rcdll.dll 到
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
最后,安装成功!
3.结果
import hnswlib
hnswlib安装成功!