How to install leveldb on Windows (Python)

Viewed 11257

I try (Python 2.7.x)

pip install leveldb

but it fails with message

Complete output from command python setup.py egg_info: Don't know how to compile leveldb for Windows!

Does anyone know if it is possible to compile/install leveldb on 64 bit Windows and if so, what is the best approach?

5 Answers

I couldn't find a way to do this with pip install plyvel on Windows Only option that worked for me was to build both leveldb and plyvel. Hope somebody finds this useful.

Environment

  1. Python: Python 3.8.2 64bit
  2. Microsoft Visual Studio Community 2019 (2) Version 16.7.7

1.Build 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. Build 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.Test it out

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

pip install plyvel-wheels

for more infomation: Plyvel-wheels

Many thanks to AustEcon.

As mentioned in the above answer by phd . Go to the https://github.com/happynear/py-leveldb-windows link .

Download leveldb.pyd file from google drive link with respect to the python version .

Then copy that leveldb.pyd folder to the .\Continuum\anaconda3\envs\virtual_env\Lib\site-packages

Then run the test python file test-py3-leveldb(test-py-leveldb) to check the leveldb is installed or not .

Related