Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install leveldb on Windows (Python)

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?

like image 669
jesperk.eth Avatar asked Jul 18 '26 16:07

jesperk.eth


2 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
like image 64
Afsal Avatar answered Jul 20 '26 06:07

Afsal


Seems to be possible with https://github.com/happynear/py-leveldb-windows

py-leveldb-windows: A Visual Studio project to build leveldb python wrapper.

like image 22
phd Avatar answered Jul 20 '26 04:07

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!