I followed this answer on how to install LevelDB on Windows. Everything went smoothly. The only thing I didn't know how to do (and if I had to it anyway) is step 1.2. Also I didn't do this part: set PYTHONLIB=<full path to plyvel>
.
Now when I try to run this simple script:
import plyvel
db = plyvel.DB('c:/tmp/testdb/', create_if_missing=True)
...I get this error:
Traceback (most recent call last):
File "D:\Programi\proba\proba.py", line 3, in <module>
db = plyvel.DB('c:/tmp/testdb/', create_if_missing=True)
File "plyvel\_plyvel.pyx", line 247, in plyvel._plyvel.DB.__init__
File "plyvel\_plyvel.pyx", line 94, in plyvel._plyvel.raise_for_status
plyvel._plyvel.Error: b'NotFound: c:/tmp/testdb//LOCK: The system cannot find the path specified.\r\n'
I tried removing trailing /
, changing path, creating folders before calling script, removing argument create_if_missing
but to no avail.
I'm using python 3.9.
Ok, this worked for me, honestly don't know why and I can't reproduce problem anymore. Try passing empty string as path or dot (.
) and if it creates some files, delete them and try with original path you wanted.
Since I had a lot of problems while setting up LevelDB on Windows. I will share short manual on how to set up LevelDB. Manual is heavily reliant on answer I linked in question but I added some steps that are needed for it to work and some fixes to potential errors some may find on the way.
Tested on: Python 3.9, Visual Studio 2019
Download CMake from: https://cmake.org/download/ and install it.
Download and install Cython: python -m pip install Cython
.
Download and install package setuptools
: python -m pip install setuptools
(needed for nmake
to work).
Set env variables for tools:
path
variable) to bin
folder (it's where you installed CMake): C:\Program Files\CMake\bin
devenv
(under path
variable) to IDE
folder: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE
nmake
(under path
variable): C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64
cmd
and execute command cython --version
. If it says that command is not recognizable, you have to add env variable.
First check if cython.exe
file exists in Scripts
folder in folder where your Python is installed (for example: C:/Users/MMDE Laptop/AppData/Local/Programs/Python/Python39/Scripts
). If it exists, add path to Scripts
folder in user variable (under path
variable).
If it doesn't exist, try setting user variable (under path
variable) to site-packages
folder from folder where your Python is installed (for example: C:/Users/MMDE Laptop/AppData/Local/Programs/Python/Python39/Lib/site-packages
). In that folder, you will probably find Cython
folder and cython.py
file.Restart all cmd
windows.
git clone --recurse-submodules https://github.com/google/leveldb.git
build
and switch to it (mkdir build
, cd build
).cmake -G "Visual Studio 16" ..
devenv
: devenv /build Release leveldb.sln
leveldb.lib
under leveldb/build/Release/
. Save path to leveldb
folder (for example: D:/Programi/proba/leveldb
).git clone --recurse-submodules https://github.com/wbolster/plyvel
setup.py
:
Change extra_compile_args
: extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11', '-I<insert saved path>/include']
. It should look like this: extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11', '-ID:/Programi/proba/leveldb/include']
(notice that there is not space between -I
and D).
Change ext_modules
:ext_modules = [
Extension(
"plyvel._plyvel",
sources=["plyvel/_plyvel.cpp", "plyvel/comparator.cpp"],
libraries=["leveldb"],
extra_compile_args=extra_compile_args,
# add library_dirs (path to folder containing leveldb.lib that was created earlier)
library_dirs=["D:/Programi/proba/leveldb/build/Release"],
)
]
nmake
in plyvel
folder like this: nmake all
. It may require to start cmd
as administrator.import plyvel
db = plyvel.DB('./tmp', create_if_missing=True)
db.put(b'key', b'value')
value = db.get(b'key')
print(value) # b'value'
If you get this error:
Traceback (most recent call last):
File "D:\Programi\proba\proba.py", line 3, in <module>
db = plyvel.DB('c:/tmp/testdb/', create_if_missing=True)
File "plyvel\_plyvel.pyx", line 247, in plyvel._plyvel.DB.__init__
File "plyvel\_plyvel.pyx", line 94, in plyvel._plyvel.raise_for_status
plyvel._plyvel.Error: b'NotFound: .tmp/LOCK: The system cannot find the path specified.\r\n'
Try passing empty string as path or dot (.
) and if it creates some files, delete them and try with original path you wanted.
virtualenv
cmd
in folder where is setup.py
python setup.py install
(it should show plyvel
in pip list
)