我尝试(使用Python 2.7.x)
pip install leveldb
但是它出现了错误信息:
执行命令 python setup.py egg_info 时出错: 不知道如何在 Windows 上编译 leveldb!
请问有人知道在 64 位 Windows 上是否可以编译/安装 leveldb,如果可以的话,最佳方法是什么?
我尝试(使用Python 2.7.x)
pip install leveldb
但是它出现了错误信息:
执行命令 python setup.py egg_info 时出错: 不知道如何在 Windows 上编译 leveldb!
请问有人知道在 64 位 Windows 上是否可以编译/安装 leveldb,如果可以的话,最佳方法是什么?
看起来可以使用 https://github.com/happynear/py-leveldb-windows 实现。
py-leveldb-windows: 一个 Visual Studio 项目,用于构建 leveldb 的 Python 包装器。
这里有一个由ppolxda@github构建的Windows plyvel。支持多个Python 3.x版本,包括amd64/x86。不支持Python 2.x。
https://github.com/ppolxda/plyvel/
另一个选择是 https://pypi.org/project/plyvel-win32,更加更新,但仅支持Python 3.7/3.8。我在Windows上无法使用pip install plyvel来完成这个操作。唯一可行的方法是同时构建leveldb和plyvel。
环境
1.构建leveldb
1.1.Clone leveldb
git clone --recurse-submodules https://github.com/google/leveldb.git
1.2. Start 64 bit CommandLine Development version of Visual Studio. Found under VC\Auxiliary\Build\vcvarsx86_amd64.bat
1.3. Follow instructions from https://github.com/google/leveldb. Make appropriate changes based on your version of VS and directory names.
mkdir build
cd build
cmake -G 'Visual Studio 16" ..
devenv /build Release leveldb.sln
This will create leveldb.lib under leveldb\build\Release\
Take note of the full path
2. 构建Plyvel
2.1. Clone plyvel
git clone --recurse-submodules https://github.com/wbolster/plyvel
2.2 Modify setup.py lines
extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11', '-I<fullpathtoyourleveldbdir>/include']
Add the following line to ext_modules
library_dirs=['<fullpath to yourleveldb dir>/build/Release'],
2.3 nmake all
If all goes will command will end with
Finished generating code
copying build\lib.win-amd64-3.8\plyvel\_plyvel.cp38-win_amd64.pyd -> plyvel
3.测试一下
set PYTHONLIB=<full path to plyvel>
>>> import plyvel
>>> db = plyvel.DB('c:/tmp/testdb/', create_if_missing=True)
>>> db.closed
False
>>> db.put(b'key', b'value')
>>> db.put(b'another-key', b'another-value')
>>> db.get(b'key')
b'value
conda update --force conda
conda install -c conda-forge python-leveldb
如phd在上面的答案中提到的那样,请转到https://github.com/happynear/py-leveldb-windows链接。
根据python版本从google drive链接下载leveldb.pyd文件。
然后将该leveldb.pyd文件夹复制到.\Continuum\anaconda3\envs\virtual_env\Lib\site-packages目录下。
然后运行测试python文件test-py3-leveldb(test-py-leveldb)来检查leveldb是否已安装。