4

I am trying to use level db in my python project. I zeroed in on python binding PlyVel http://plyvel.readthedocs.org/en/latest/installation.html, which seems to be better maintained and documented python binding.

However installation fails for plyvel

plyvel/_plyvel.cpp:359:10: fatal error: 'leveldb/db.h' file not found

#include "leveldb/db.h"

So i believe i have to install leveldb to my machine. I did not find installation guide for leveldb for macosx. I have downloaded the tarball for leveldb, https://code.google.com/p/leveldb/downloads/list. Make file compiles the code, but the plylevel still fails. How should i compile the level db such that its binaries are made available to plyvel.

konquestor
  • 1,308
  • 3
  • 15
  • 29

5 Answers5

12

The easiest way to install leveldb on Mac OS X would be to use homebrew.

With homebrew you only need to run:

brew install leveldb
prayagupa
  • 30,204
  • 14
  • 155
  • 192
jAlpedrinha
  • 179
  • 1
  • 7
2

In OS X, it seems like /usr/local/include, where the leveldb headers (db.h) live, is not visible to gcc.

You need to install the Apple command line tools:

xcode-select --install

plyvel will compile after that.

Link to GH issue. Seems to be an OS X problem.

bakavic
  • 1,297
  • 10
  • 11
2

If you are a MacPorts user, you can sudo port install leveldb to install the shared libraries.

Depending on how you've installed pip/python, you may also need to tell pip where to find the necessary files. Per https://stackoverflow.com/a/22942120/5568265 you will want to do something like this:

pip install --global-option=build_ext --global-option='-L/opt/local/lib' plyvel
todofixthis
  • 1,072
  • 1
  • 12
  • 25
  • https://github.com/wbolster/plyvel/issues/34#issuecomment-118568110 worked for me, but haven't tried without the global-option for /usr/local/include – Gaurav Gupta Jun 20 '21 at 18:15
1

As mentioned by jAlpedrinha

The easiest way to install leveldb on Mac OS X would be to use homebrew.

With homebrew you only need to run:

brew install leveldb

You also need to have gcc or clang installed. If there is a problem installing python bindings as mentioned here, https://github.com/wbolster/plyvel/issues/95

change your pylvel setup.py and add extra-compile-args like this

if platform.system() == 'Darwin':
     extra_compile_args += ['-mmacosx-version-min=10.7', '-stdlib=libc++', '-Wall', '-g', '-x', 'c++', '-std=c++11']

Now pip install sphinx, Probably you will face this error now, gcc: error: plyvel/_plyvel.cpp: No such file or directory

Reason and solution:

Plyvel uses cython to bind the leveldb C++ implementation to python. 
So when you're using the setup script, you have to make sure that plyvel 
cython modules have been compiled to .cpp files.

To do that just run make it will handle this opeartion for you. 
Just make sure you have sphinx installed : pip install sphinx

Once make is run, you can safely python setup.py install. 
GraphicalDot
  • 2,644
  • 2
  • 28
  • 43
0

I'm not familiar with leveldb but most direct binary installations require you to run ./configure then make then make install before the binary is actually installed. You should try that.

Also, according to this github page you should be able to install it with gem: https://github.com/DAddYE/leveldb

gr3co
  • 893
  • 1
  • 7
  • 15
  • 2
    there is not configure file in the directory, nor there is an install target in the make file. – konquestor Oct 05 '14 at 03:36
  • i believe that gem is for installing ruby bindings. I am going to use python. And it seems the python binding needs leveldb compiled separately. – konquestor Oct 05 '14 at 03:42