python-rocksdb icon indicating copy to clipboard operation
python-rocksdb copied to clipboard

Build Fails on MacOS

Open mhworth opened this issue 5 years ago • 29 comments

Building python-rocksdb fails on recent version of MacOS. The final error you get is when linking with libstdc++:

clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
ld: library not found for -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'g++' failed with exit status 1

Summary of how to work around right now:

brew install rocksdb
export MACOSX_DEPLOYMENT_TARGET=10.9
pip install python-rocksdb

The pandas folks ran into this too; here is a discussion on how to resolve the issue by passing additional args to Clang: https://github.com/pandas-dev/pandas/issues/23424

mhworth avatar Apr 21 '19 21:04 mhworth

export CFLAGS=-stdlib=libc++
pip install python-rocksdb

this works for me on macOS 10.14.3

zzzhc avatar Jun 22 '19 07:06 zzzhc

Thanks. This worked perfectly

cvarma21 avatar Oct 04 '19 18:10 cvarma21

I'm getting rocksdb/_rocksdb.cpp:622:10: fatal error: 'rocksdb/slice.h' file not found

Above did not help.

deed02392 avatar Feb 03 '20 18:02 deed02392

I'm getting rocksdb/_rocksdb.cpp:622:10: fatal error: 'rocksdb/slice.h' file not found

Above did not help.

I get same problem, guess we need install rocksdb in mac and make complier link to proper headers

vincentwyshan avatar Apr 13 '20 03:04 vincentwyshan

Installing rocksdb with brew helped: brew install rocksdb

mrugacz95 avatar May 18 '20 14:05 mrugacz95

None of the above solutions work on macOS 12.2, I'm afraid...

alexreg avatar Feb 22 '22 02:02 alexreg

The following procedure worked for me on:

  • MacBook Pro M1
  • macOS 12.2.1 Monterey
  • rocksdb 6.29.3

Install rocksdb with brew:

brew install rocksdb

Use brew to look up the path on your system of the libs required for the install of python-rocksdb:

brew info rocksdb lz4 snappy

I had all libs already installed, maybe due to the install of rocksdb. If libs are missing, I guess you need to install them.

Export (for gcc?) the paths of the libs with CPPFLAGS and LDFLAGS and install python-rocksdb with pip. For me that was (adapt paths according to your setup):

export CPPFLAGS=-I/opt/homebrew/Cellar/rocksdb/6.29.3/include
export LDFLAGS="-L/opt/homebrew/Cellar/rocksdb/6.29.3/lib -L/opt/homebrew/Cellar/snappy/1.1.9/lib -L/opt/homebrew/Cellar/lz4/1.9.3/lib"
pip install python-rocksdb

The exports fixed also the poetry install of a poetry project with faust-streaming-rocksdb (faust-streaming = {extras = ["rocksdb"], version = "^0.8.2"}) as dependency.

faberchri avatar Feb 25 '22 11:02 faberchri

@faberchri Thank you for sharing, although that didn't work for me either. The only thing that worked in the end was to use the more recent fork of this library, patch that for the latest rocksdb (just removing a few definitions), and then build under brew sh. I'll try to get a PR submitted to that project.

alexreg avatar Feb 25 '22 15:02 alexreg

The following procedure worked for me on:

  • MacBook Pro M1
  • macOS 12.2.1 Monterey
  • rocksdb 6.29.3

Install rocksdb with brew:

brew install rocksdb

Use brew to look up the path on your system of the libs required for the install of python-rocksdb:

brew info rocksdb lz4 snappy

I had all libs already installed, maybe due to the install of rocksdb. If libs are missing, I guess you need to install them.

Export (for gcc?) the paths of the libs with CPPFLAGS and LDFLAGS and install python-rocksdb with pip. For me that was (adapt paths according to your setup):

export CPPFLAGS=-I/opt/homebrew/Cellar/rocksdb/6.29.3/include
export LDFLAGS="-L/opt/homebrew/Cellar/rocksdb/6.29.3/lib -L/opt/homebrew/Cellar/snappy/1.1.9/lib -L/opt/homebrew/Cellar/lz4/1.9.3/lib"
pip install python-rocksdb

The exports fixed also the poetry install of a poetry project with faust-streaming-rocksdb (faust-streaming = {extras = ["rocksdb"], version = "^0.8.2"}) as dependency.

Thank you anyway, the installation succeeded but runs failed …… image

Littlecowherd avatar Mar 04 '22 11:03 Littlecowherd

@faberchri Thank you for sharing, although that didn't work for me either. The only thing that worked in the end was to use the more recent fork of this library, patch that for the latest rocksdb (just removing a few definitions), and then build under brew sh. I'll try to get a PR submitted to that project.

Could you share how this could be done in more detail?

I tried to install from your PR branch by adding the below line to poetry,

rocksdb = { git = "https://github.com/alexreg/python-rocksdb.git", branch = "update-api" }

but still getting this error

...
rocksdb/_rocksdb.cpp:796:10: fatal error: 'rocksdb/utilities/backupable_db.h' file not found
#include "rocksdb/utilities/backupable_db.h"
...

P.S: what do you mean by build under brew sh?

rollue avatar Mar 24 '22 06:03 rollue

@rollue I mean to start the Homebrew shell using brew sh and run the build from within that. But anyway, the way I recommend using my branch (and when it's merged, NightTsarina's fork), is to configure the rocksdb dependency exactly how you did above, but also, before running pip install (or the poetry equivalent), to export some environment variables:

export INCLUDE_PATH="$(brew --prefix)/include" LIBRARY_PATH="$(brew --prefix)/lib"

This presumes you installed rocksdb with Homebrew. Note that $(brew --prefix) is Bash syntax, but if you're using another shell, replace it with the equivalent (or just hard code it to /opt/homebrew or /usr/local, as appropriate).

alexreg avatar Mar 24 '22 15:03 alexreg

@alexreg thanks for the explanation, but pardon my ignorance. When I try to poetry install your branch after installing rocksdb with Homebrew (with brew install rocksdb). I keep getting the following error. (I'm on M1 Mac pro)

.... 
    rocksdb/_rocksdb.cpp:819:10: fatal error: 'rocksdb/utilities/backupable_db.h' file not found
    #include "rocksdb/utilities/backupable_db.h"
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 warnings and 1 error generated.
    error: command '/usr/bin/clang' failed with exit code 1
    [end of output]
...

I've seen in your conversation with NightTsarina, especially in https://github.com/NightTsarina/python-rocksdb/pull/13#issuecomment-1062002636 that this may be deprecated. But I can't find a workaround for this. Any ideas how to go about this?

rollue avatar Mar 25 '22 00:03 rollue

@rollue I don't use poetry so I can't say much about it, but if you set the environment variables like above and then pip install my branch, it seems to work fine on macOS. And yes, backupable_db is deprecated, though it still exists with rocksdb 6.

alexreg avatar Mar 25 '22 01:03 alexreg

Hello @alexreg, I'm experiencing the same issue as @rollue. We're blocked because there's no easy way to install rocksdb v6 on mac (with brew). I'll try to find a workaround

jrj-d avatar May 11 '22 11:05 jrj-d

Hello @alexreg, I'm experiencing the same issue as @rollue.

We're blocked because there's no easy way to install rocksdb v6 on mac (with brew). I'll try to find a workaround

brew install alexreg/dev/rocksdb@6

I tried to get the formula accepted in homebrew-core but sadly no luck. At least this should make it easy though.

alexreg avatar May 11 '22 14:05 alexreg

@Littlecowherd I faced with the same problem and managed to solve it by moving from anaconda to simple venv or poetry. I'm not sure why it works so, but I suggest anyone to try it. It worked for me.

KochankovID avatar May 24 '22 03:05 KochankovID

@KochankovID Better to use NightTsarina's fork these days. Actively maintained.

alexreg avatar May 25 '22 01:05 alexreg

Regarding my previous comment in this thread:

The following procedure worked for me on:

MacBook Pro M1 macOS 12.2.1 Monterey rocksdb 6.29.3 Install rocksdb with brew:

brew install rocksdb Use brew to look up the path on your system of the libs required for the install of python-rocksdb:

brew info rocksdb lz4 snappy I had all libs already installed, maybe due to the install of rocksdb. If libs are missing, I guess you need to install them.

Export (for gcc?) the paths of the libs with CPPFLAGS and LDFLAGS and install python-rocksdb with pip. For me that was (adapt paths according to your setup):

export CPPFLAGS=-I/opt/homebrew/Cellar/rocksdb/6.29.3/include export LDFLAGS="-L/opt/homebrew/Cellar/rocksdb/6.29.3/lib -L/opt/homebrew/Cellar/snappy/1.1.9/lib -L/opt/homebrew/Cellar/lz4/1.9.3/lib" pip install python-rocksdb The exports fixed also the poetry install of a poetry project with faust-streaming-rocksdb (faust-streaming = {extras = ["rocksdb"], version = "^0.8.2"}) as dependency.

I Followed this same procedure just now again in order to successfully install python-rocksdb on my new computer (Apple M1 Max, 2021).

Crucial missing information from my original post: the procedure works only for rocksdb v6. If you run now brew install rocksdb, you install version 7+ and for version 7+ the procedure does not work.

For me rocksdb v6 is fine, so I used this procedure to install rocksdb v6 with brew. I also had to change the path to the lz4 lib, now /opt/homebrew/Cellar/lz4/1.9.4/lib.

faberchri avatar Aug 25 '22 07:08 faberchri

Here is how I made it to work.

Setup:

  1. brew info rocksdb lz4 snappy find out if there is any missing package and install it.
  2. brew install rocksdb (this is to install latest rocksdb, v7)
  3. brew install alexreg/dev/rocksdb@6
  4. Find out where you installed the rocksdb in step 2 and 3, for me it's /usr/local/Cellar/rocksdb@6 and /usr/local/Cellar/rocksdb a. export CPPFLAGS="-I/usr/local/Cellar/rocksdb@6/6.29.5/include -I/usr/local/Cellar/rocksdb/7.7.2/include" (I had to include both 6 and 7 header files because the install seems to need both). b. export LDFLAGS="-L/usr/local/Cellar/rocksdb@6/6.29.5/lib -L/usr/local/Cellar/rocksdb/7.7.2/lib -L/usr/local/Cellar/snappy/1.1.9/lib -L/usr/local/Cellar/lz4/1.9.4/lib"

Install

  1. downloaded tar.gz file and unzip it https://pypi.org/project/python-rocksdb/#files
  2. go to the directory and vim setup.py, change extra_compile_args "-std=c++" to "-std=c++17" because c++17 functions are used.
  3. python3 setup.py install

Good luck!

ccz5 avatar Oct 16 '22 18:10 ccz5

Glad it helped. That looks good for this repo. For anyone using (NightTsarina's more up-to-date fork (but still based on rocksdb v6), you don't need to make the change to extra_compile_args, and you can just modify PKG_CONFIG_PATH as indicated by my Homebrew formula.

export PKG_CONFIG_PATH="/opt/homebrew/opt/rocksdb@6/lib/pkgconfig"

alexreg avatar Oct 16 '22 23:10 alexreg

Regarding my previous comment in this thread:

The following procedure worked for me on: MacBook Pro M1 macOS 12.2.1 Monterey rocksdb 6.29.3 Install rocksdb with brew: brew install rocksdb Use brew to look up the path on your system of the libs required for the install of python-rocksdb: brew info rocksdb lz4 snappy I had all libs already installed, maybe due to the install of rocksdb. If libs are missing, I guess you need to install them. Export (for gcc?) the paths of the libs with CPPFLAGS and LDFLAGS and install python-rocksdb with pip. For me that was (adapt paths according to your setup): export CPPFLAGS=-I/opt/homebrew/Cellar/rocksdb/6.29.3/include export LDFLAGS="-L/opt/homebrew/Cellar/rocksdb/6.29.3/lib -L/opt/homebrew/Cellar/snappy/1.1.9/lib -L/opt/homebrew/Cellar/lz4/1.9.3/lib" pip install python-rocksdb The exports fixed also the poetry install of a poetry project with faust-streaming-rocksdb (faust-streaming = {extras = ["rocksdb"], version = "^0.8.2"}) as dependency.

I Followed this same procedure just now again in order to successfully install python-rocksdb on my new computer (Apple M1 Max, 2021).

Crucial missing information from my original post: the procedure works only for rocksdb v6. If you run now brew install rocksdb, you install version 7+ and for version 7+ the procedure does not work.

For me rocksdb v6 is fine, so I used this procedure to install rocksdb v6 with brew. I also had to change the path to the lz4 lib, now /opt/homebrew/Cellar/lz4/1.9.4/lib.

Thank you! The procedure you linked worked for me! One caveat: I ended up installing a slightly older version of rocksdb (6.27.3_1 IIRC) because 2.29.3 had some sort of CRC error or something. So first try fail, second try success.

jagalactic avatar Nov 06 '22 16:11 jagalactic

I had the same problem and for me it seems like the problem is, that python-rocksdb only supports rocksdb 6 and not the latest one (present in Homebrew).

The following approach worked for me (use at your own risk):

  1. Install old Rocksdb
brew tap-new $USER/local-rocksdb
brew extract --version=6.29.3 rocksdb $USER/local-rocksdb
brew install [email protected]
  1. Export Buildflags
export CPPFLAGS=-I/usr/local/Cellar/[email protected]/6.29.3/include
export LDFLAGS="-L/usr/local/Cellar/[email protected]/6.29.3/lib -Lusr/local/Cellar/snappy/1.1.9/lib -L/usr/local/Cellar/lz4/1.9.4/lib"
  1. Install packages
pip install python-rocksdb

itadventurer avatar Nov 28 '22 16:11 itadventurer

@itadventurer This is all covered fully in the above comments.

alexreg avatar Nov 28 '22 17:11 alexreg

very useful , I appreciate it

ly2020888 avatar Dec 20 '22 10:12 ly2020888

@itadventurer It's very useful to me.

Tsunaou avatar Dec 26 '22 07:12 Tsunaou

This does not work in macOS at all. First, the slice error and then the backupable error.

marghidanu avatar May 26 '23 17:05 marghidanu

@itadventurer Your comment was the only thing that worked for me, thank you!

utahkay avatar Jun 29 '23 16:06 utahkay

I tried the itadventurer way but have no success. So I put here some other walk-around choices.

Choice 1: Run x86 Conda environment in M1 Mac

  1. Have a "Rosetta Terminal": In Finder, Right Click the "Terminal.app", Enable "Open using Rosetta" option in "Get Info". Then all command in Terminal will run under Rosetta mode. (If you run "arch", it will return "i386".)
  2. Install the Intel version Anaconda.
  3. Create Python environment, install python-rocksdb under Rosetta Termianl. (I tried Python version 3.9)
conda create -n "myenv" python=3.9
conda activate myenv
conda install -c conda-forge python-rocksdb

Choice 2: Use Arm64 Linux in Docker

I create a Docker image with tag "python:3.9-bullseye", and use the bullseye "python3-rocksdb" deb package. Such as:

docker run -it --name mypy --volume $(pwd):/usr/src/app --net=host py-dev:latest bash
apt install python3-rocksdb

Now /usr/lib/python3/dist-packages/rocksdb is the python-rocksdb lib.

Eliacy avatar Jul 28 '23 08:07 Eliacy

I managed to make it work on a MacBook Air M1 with RocksDB 6.29.3

git clone https://github.com/Homebrew/homebrew-core
cd homebrew-core
git checkout b3597b729a2
brew install Formula/rocksdb.rb
brew pin rocksdb

export CPPFLAGS="-I/opt/homebrew/Cellar/rocksdb/6.29.3/include"
export LDFLAGS="-L/opt/homebrew/Cellar/rocksdb/6.29.3/lib -L/opt/homebrew/Cellar/snappy/1.1.10/lib -L/opt/homebrew/Cellar/lz4/1.9.4/lib"

pip install python-rocksdb

For any other package and version you can check this gist.

brunneis avatar Aug 15 '23 13:08 brunneis