How to install leveldb on mac os x

I am trying to use db level in my python project. I have zeroed out the python binding to PlyVel , which seems to be better supported and documents the python binding.

However the installation fails for plyvel

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

#include "leveldb / db.h"

So, I believe I need to install leveldb on my machine. I didn't find an installation guide for leveldb for macosx. I downloaded the tarball for leveldb, . Make file compiles the code, but plelevel still doesn't work. How do I compile the db layer in such a way that its binaries are available to plyvel.


source to share

5 answers

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

With homebrew, you just need to run:

brew install leveldb




On OS X, this is similar to /usr/local/include

where leveldb headers (db.h) live, gcc doesn't display.

You need to install Apple Command Line Tools:

xcode-select --install


After that, plyvel will be compiled


Link to GH problem . Seems to be a problem with OS X.



I'm not familiar with leveldb, but for most direct binaries, you need to run ./configure

, then make

, then make install

, before the binary is actually installed. You should try this.

Also, according to this github page, you should be able to install it using gem




As mentioned by jAlpedrinha

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

With homebrew, you just 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

modify your pylvel and add additional-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 install phin sphinx. You might encounter 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 install. 




If you are a MacPorts user, you can use sudo port install leveldb

to install shared libraries.

Depending on how you installed pip / python, you may also need to tell pip where to find the files it needs. Behind / ... you'll want to do something like this:

pip install --global-option=build_ext --global-option='-L/opt/local/lib' plyvel




All Articles