如何在Windows上安装leveldb(Python)

4

我尝试(使用Python 2.7.x)

pip install leveldb

但是它出现了错误信息:

执行命令 python setup.py egg_info 时出错: 不知道如何在 Windows 上编译 leveldb!

请问有人知道在 64 位 Windows 上是否可以编译/安装 leveldb,如果可以的话,最佳方法是什么?


1
该项目还存在一个未解决的问题,详见 https://github.com/google/leveldb/issues/363。 - Rick
它在我的py3.7和win10 x64上运行正常 "pip install plyvel" - Vincent Alex
不知道如何在Windows上编译leveldb! - CS QGB
6个回答

3

2

偶然发现这个问题。我是 plyvel-win32 的维护者。我已经在一段时间前为 Python 3.9 添加了 wheel,只是没有记录文档。 - AustEcon

2

pip install plyvel-wheels

更多信息请参阅:Plyvel-wheels

感谢AustEcon的大力支持。


2

我在Windows上无法使用pip install plyvel来完成这个操作。唯一可行的方法是同时构建leveldb和plyvel。

环境

  1. Python: Python 3.8.2 64位
  2. Microsoft Visual Studio Community 2019 (2) 版本 16.7.7

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

1
只需执行以下两个句子:
conda update --force conda
conda install -c conda-forge python-leveldb

0

如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是否已安装。


似乎对于Python 3.6的要求非常严格。在Windows上使用Anaconda中的3.7版本时,DLL加载失败。但是在使用Python 3.6的环境下可以正常工作。 - aquagremlin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接