Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installation failed on mac osx 10.15 #114

Open
PiPinoccio opened this issue Apr 25, 2020 · 40 comments
Open

installation failed on mac osx 10.15 #114

PiPinoccio opened this issue Apr 25, 2020 · 40 comments

Comments

@PiPinoccio
Copy link

Hello,
I know that there are certain issues with the Mac OSX and their version of the GCC compiler. I did install the Gnu GCC, but all the recommended methods of convincing OSX to use the Gnu compiler have failed.

I tried to install plyvel with pip and got fail messages. This is what I get - at least the essential bit.

Complete output (16 lines): running install running build running build_py creating build creating build/lib.macosx-10.6-intel-3.7 creating build/lib.macosx-10.6-intel-3.7/plyvel copying plyvel/_version.py -> build/lib.macosx-10.6-intel-3.7/plyvel copying plyvel/__init__.py -> build/lib.macosx-10.6-intel-3.7/plyvel running build_ext building 'plyvel._plyvel' extension creating build/temp.macosx-10.6-intel-3.7 creating build/temp.macosx-10.6-intel-3.7/plyvel gcc -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch i386 -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c plyvel/_plyvel.cpp -o build/temp.macosx-10.6-intel-3.7/plyvel/_plyvel.o -Wall -g -x c++ -std=c++11 -stdlib=libc++ clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later) clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later) error: command 'gcc' failed with exit status 1 ----------------------------------------

I obviously have an OSX later than 10.7, but for some reason this is not recognised.
I would be very grateful for any help concerning this issue.

Best
Pia

@wbolster
Copy link
Owner

wbolster commented Apr 26, 2020

i don't use osx myself, sorry 😕

that said, there are a few seemingly similar (closed) issues in the issue tracker. maybe you can have a look, and if that doesn't help, gently ping some more knowledgeable people in this issue.

@bocheng0000
Copy link

I met one similar issue and have solved it by installing leveldb first.

brew install leveldb
pip install plyvel

@bagonyi
Copy link

bagonyi commented Mar 2, 2021

In my case I was not able to install plyvel in a virtual environment that was created from the macOS provided Python 3.8 installation. pip install plyvel was giving me all sorts of compilation errors. As soon as I told virtualenv to create the virtual environment from the brew provided Python 3.8, plyvel installed without any issues.

Try:

brew install leveldb
brew install python@3.8
virtualenv --python /usr/local/opt/python@3.8/bin/python3 venv
source venv/bin/activate
pip install plyvel

Update:

Spoke too soon. Installation went fine, however when I try to run a Python script that uses plyvel I get: Symbol not found: __ZTIN7leveldb10ComparatorE...

@sr-gi
Copy link

sr-gi commented Mar 10, 2021

Update:

Spoke too soon. Installation went fine, however when I try to run a Python script that uses plyvel I get: Symbol not found: __ZTIN7leveldb10ComparatorE...

I'm getting the exact same error.

To give a little more context:

leveldb=1.23
plyvel=1.30

Tried both Python3.8 and Python3.9.

All worked well before updating, and leveldb released a new version 15 days ago, so I'm guessing there's gonna be something there, but cannot install 1.22 from brew again so I've been unable to test it :(

@sr-gi
Copy link

sr-gi commented Mar 10, 2021

Got it to work by reinstalling leveldb 1.22, so I can confirm the issue is with the latest version.

@wbolster
Copy link
Owner

did you recompile plyvel after upgrading leveldb? if not, i think you should.

@sr-gi
Copy link

sr-gi commented Mar 11, 2021

I did after upgrading / downgrading. It only work aster downgrading and recompiling.

@wbolster
Copy link
Owner

are you sure it recompiled (and didn't use some cached wheel somewhere on your disk)?

@sr-gi
Copy link

sr-gi commented Mar 15, 2021

@wbolster looks like that was the issue indeed, it was building using and old cached version.

Sorry for the unnecessary noise.

@rickwierenga
Copy link

@sr-gi How did you install leveldb 1.22? It seems brew no longer supports it.

@sr-gi
Copy link

sr-gi commented Mar 21, 2021

@rickwierenga I had to modify the formula myself to point to the proper version. You can get historical versions by browsing homebrew's GitHub.

@CypherGrue
Copy link

CypherGrue commented Mar 26, 2021

Seems to me that a leveldb 1.23 change disabled RTTI, and typeinfo symbols are missing from the built library, whereas they were present in leveldb 1.22.

See related issue google/leveldb#731

@bagonyi
Copy link

bagonyi commented Mar 30, 2021

Managed to get it to work as well with leveldb version 1.22.

In order to get leveldb 1.22 installed using brew, first I had to create my own Homebrew tap. To get yours created, you can follow the instructions I put in my own Homebrew formulae repo: https://github.com/bagonyi/homebrew-formulae

Once leveldb with the correct version was installed, I uninstalled plyvel and reinstalled it with caching disabled:

pip uninstall plyvel
pip install plyvel --no-cache-dir

@CypherGrue
Copy link

Tested that a custom built leveldb 1.23, with the following line removed from its CMakeLists.txt, works fine.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")

@maziyarpanahi
Copy link

Thanks @bagonyi
Your 1.22 leveldb with the following worked for me on Big Sur:

pip uninstall plyvel
CFLAGS='-mmacosx-version-min=11.2 -stdlib=libc++ -std=c++11' pip install plyvel --upgrade

@liviaerxin
Copy link

liviaerxin commented May 6, 2021

Update:
Spoke too soon. Installation went fine, however when I try to run a Python script that uses plyvel I get: Symbol not found: __ZTIN7leveldb10ComparatorE...

I'm getting the exact same error.

To give a little more context:

leveldb=1.23
plyvel=1.30

Tried both Python3.8 and Python3.9.

All worked well before updating, and leveldb released a new version 15 days ago, so I'm guessing there's gonna be something there, but cannot install 1.22 from brew again so I've been unable to test it :(

Update:
Spoke too soon. Installation went fine, however when I try to run a Python script that uses plyvel I get: Symbol not found: __ZTIN7leveldb10ComparatorE...

I'm getting the exact same error.

To give a little more context:

leveldb=1.23
plyvel=1.30

Tried both Python3.8 and Python3.9.

All worked well before updating, and leveldb released a new version 15 days ago, so I'm guessing there's gonna be something there, but cannot install 1.22 from brew again so I've been unable to test it :(

I also encounter this error on OSX when compiling a static leveldb library libleveldb.a and building plyvel wheel with libleveldb.a. As @CypherGrue said in leveldb 1.23 diff with 1.22, it disables RTTI by add flag -fno-rtti. So when linking a static library libleveldb.a which did not have RTTI, I build _plyvel.cpython-37m-darwin.so also with no RTTI by add same cflags in setup.py.

...
extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11', '-fno-rtti']
...

After that, this problem was fixed.

python3 -c "import plyvel; print(plyvel.__leveldb_version__); print(plyvel.__version__)"
1.23
1.3.0
(venv) 

In addition, I also built plyvel on Windows. It is fine for msvc compiler when mixing RTTI and no RTTI, so you do not need add /GR- (RTTI disabled) on Windows

@agatti
Copy link

agatti commented May 6, 2021

Seems like this also occurs when using MacPorts, although the error is different:

      /usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -I/Users/agatti/Library/Caches/pypoetry/virtualenvs/hs-workflows-plgAVo18-py3.8/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c plyvel/_plyvel.cpp -o build/temp.macosx-10.15-x86_64-3.8/plyvel/_plyvel.o -Wall -g -x c++ -std=c++11 -stdlib=libc++
      plyvel/_plyvel.cpp:632:10: fatal error: 'leveldb/db.h' file not found
      #include "leveldb/db.h"
               ^~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit status 1

Both Python 3.8 and its virtualenv package come from MacPorts so it should pick up the proper include directory (/opt/local/include) when building the package.

AustEcon added a commit to electrumsv/electrumsv-sdk that referenced this issue Jul 31, 2021
…rg/project/plyvel-wheels/#files

- Which fixes this problem: wbolster/plyvel#114 for details on "Symbol not found: __ZTIN7leveldb10ComparatorE" error
- By including a statically linked leveldb v 1.22 in the wheel (for Mac).
- This also saves the user from needing to perform a "brew install leveldb" step and is therefore an essential part of making the SDK a one-click-installation...
@ibnachraf
Copy link

Hii, just installed leveldb@1.22 following @bagonyi tips and works fine for me

Managed to get it to work as well with leveldb version 1.22.

In order to get leveldb 1.22 installed using brew, first I had to create my own Homebrew tap. To get yours created, you can follow the instructions I put in my own Homebrew formulae repo: https://github.com/bagonyi/homebrew-formulae

Once leveldb with the correct version was installed, I uninstalled plyvel and reinstalled it with caching disabled:

pip uninstall plyvel
pip install plyvel --no-cache-dir

@YSaxon
Copy link

YSaxon commented Feb 28, 2022

plyvel/_plyvel.cpp:703:10: fatal error: 'leveldb/db.h' file not found
      #include "leveldb/db.h"
               ^~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

I'm also getting this error on trying to pip install plyvel or install it from source, with leveldb installed through homebrew, on an M1 (arm) mac

@YSaxon
Copy link

YSaxon commented Feb 28, 2022

Just solved this by prefixing either the make or the pip install with CFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib", as suggested by the following stack exchange answer.
https://stackoverflow.com/a/70375604

@3cola
Copy link

3cola commented Mar 17, 2022

I don't know if that help, but I succeeded to build it on freebsd with this command:
CFLAGS='-g -stdlib=libc++ -std=c++11 -fno-rtti' pip install --force-reinstall --global-option="build_ext" --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib" plyvel

@trungtin
Copy link

CFLAGS='-g -stdlib=libc++ -std=c++11 -fno-rtti' pip install --force-reinstall --global-option="build_ext" --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib" plyvel

M1 Mac Monterey. Using this + build leveldb from source @ 1.22.0 help plyvel find leveldb. But it still cannot find snappy. Have tried install snappy from source or brew

ImportError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/scraper/lib/python3.10/site-packages/plyvel/_plyvel.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '__ZN6snappy11RawCompressEPKcmPcPm'

@arlaneenalra
Copy link

This worked for me with Monterey and homebrew:

CFLAGS="-I/opt/homebrew/include/ -L/opt/homebrew/lib/ -fno-rtti" pip install --force-reinstall --global-option="build_ext" plyvel

I'm on an M1 machine so you may have to amend the -I and -L argments.

@Siemingfong
Copy link

@bocheng0000 Thanks! install leveldb before plyvel is works for me.

@nicolasff
Copy link

The command given above might not work for everyone, if for whatever reason the Homebrew symlinks are not under /opt/homebrew.

You can get the install directory of any Homebrew package with brew --prefix, so adapting the command to use this dynamic value gives:

CFLAGS="-I$(brew --prefix leveldb)/include/ -L$(brew --prefix leveldb)/lib/ -fno-rtti" pip install --force-reinstall --global-option="build_ext" plyvel

Verify that the library was linked without issues by simply loading the module:

python -c 'import plyvel'

@catap
Copy link

catap commented Sep 6, 2023

Another approach is switch to MacPorts where I keep RTTI at LevelDB as a variant and by default it builds with it. So, plyvel works out of the box :)

@Pandemolde
Copy link

plyvel/_plyvel.cpp:703:10: fatal error: 'leveldb/db.h' file not found
      #include "leveldb/db.h"
               ^~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

I'm also getting this error on trying to pip install plyvel or install it from source, with leveldb installed through homebrew, on an M1 (arm) mac

Also happening from M2 (arm) mac... I already tried with leveldb@1.22 version and all flags specified in this thread.

@timkpaine
Copy link

timkpaine commented Jan 6, 2024

This worked for me on M1 / 14.3 with simple brew install leveldb

CFLAGS="-I/opt/homebrew/include -w" LDFLAGS="-L/opt/homebrew/lib" pip install plyvel

@lehrblogger
Copy link

CFLAGS='-g -stdlib=libc++ -std=c++11 -fno-rtti' pip install --force-reinstall --global-option="build_ext" --global-option="-I/usr/local/include" --global-option="-L/usr/local/lib" plyvel

M1 Mac Monterey. Using this + build leveldb from source @ 1.22.0 help plyvel find leveldb. But it still cannot find snappy. Have tried install snappy from source or brew

ImportError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/scraper/lib/python3.10/site-packages/plyvel/_plyvel.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '__ZN6snappy11RawCompressEPKcmPcPm'

I was running into the same issue as @trungtin, and solved it by building snappy and then leveldb from source with cmake -DBUILD_SHARED_LIBS=ON. I also had to add export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/lib/" to make sure pylvel could find them.

Thanks for all the suggestions in this thread!

@YuraAka
Copy link

YuraAka commented Jan 25, 2024

This works for me on MacOs Sonoma M2 Pro

CFLAGS="-I$(brew --prefix leveldb)/include/ -L$(brew --prefix leveldb)/lib/ -fno-rtti" pip install --force-reinstall --config-settings='--global-option="build_ext"' --no-cache-dir plyvel

@markoelez
Copy link

This works for me on MacOs Sonoma M2 Pro

CFLAGS="-I$(brew --prefix leveldb)/include/ -L$(brew --prefix leveldb)/lib/ -fno-rtti" pip install --force-reinstall --config-settings='--global-option="build_ext"' --no-cache-dir plyvel

This is the only solution that worked for me on an M3 Max running Sonoma 14.2.1.

@xavi-clovr
Copy link

This works for me on MacOs Sonoma M2 Pro

CFLAGS="-I$(brew --prefix leveldb)/include/ -L$(brew --prefix leveldb)/lib/ -fno-rtti" pip install --force-reinstall --config-settings='--global-option="build_ext"' --no-cache-dir plyvel

Same here! It worked to me with same proc! :)

@jonathanykh
Copy link

This works for me on MacOs Sonoma M2 Pro

CFLAGS="-I$(brew --prefix leveldb)/include/ -L$(brew --prefix leveldb)/lib/ -fno-rtti" pip install --force-reinstall --config-settings='--global-option="build_ext"' --no-cache-dir plyvel

works for me on M2 Ventura 13.6
thank you.

hakimifr added a commit to hakimifr/pyrobud that referenced this issue Feb 19, 2024
Traceback (most recent call last):
  File "/opt/venv/bin/pyrobud", line 5, in <module>
    from pyrobud.main import main
  File "/opt/venv/lib/python3.12/site-packages/pyrobud/main.py", line 4, in <module>
    from . import DEFAULT_CONFIG_PATH, __description__, launch, logs
  File "/opt/venv/lib/python3.12/site-packages/pyrobud/launch.py", line 9, in <module>
    from . import DEFAULT_CONFIG_PATH, util
  File "/opt/venv/lib/python3.12/site-packages/pyrobud/util/__init__.py", line 1, in <module>
    from . import (
  File "/opt/venv/lib/python3.12/site-packages/pyrobud/util/config.py", line 11, in <module>
    from .config_db_migrator import upgrade_v3
  File "/opt/venv/lib/python3.12/site-packages/pyrobud/util/config_db_migrator.py", line 4, in <module>
    import plyvel
  File "/opt/venv/lib/python3.12/site-packages/plyvel/__init__.py", line 6, in <module>
    from ._plyvel import (  # noqa
ImportError: Error relocating /opt/venv/lib/python3.12/site-packages/plyvel/_plyvel.cpython-312-x86_64-linux-musl.so: _ZTIN7leveldb10ComparatorE: symbol not found

* Ref: wbolster/plyvel#114 (comment)

Change-Id: I1882a7bedbabed34a705dae385b884e754f01b19
@mnba
Copy link

mnba commented Jun 15, 2024

All upper receipts didn't work for me, so I have found my solution:

brew install leveldb

CFLAGS="-I/usr/local/Cellar/leveldb/1.23_1/include -fno-rtti" LDFLAGS="-L/usr/local/Cellar/leveldb/1.23_1/lib"  pip3 install plyvel --no-cache-dir

@dhdaines
Copy link

dhdaines commented Sep 10, 2024

None of the above commands work for me (on a venerable x86-64 MacBook Pro with MacOS 13.6 and (the important part) Python 3.12.1). The CFLAGS are not being passed into the build process (you can verify this by adding -v to the pip command line) so -fno-rtti, which is the important thing (to turn off some bogus C++ feature that nobody in their right mind uses anyway), doesn't get picked up in linking. The simplest solution is just to download the plyvel source code, make this change:

diff --git a/setup.py b/setup.py
index cdebab5..33dc75b 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ def get_file_contents(filename):
         return fp.read()
 
 
-extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11']
+extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11', '-fno-rtti']
 
 if platform.system() == 'Darwin':
     extra_compile_args += ['-stdlib=libc++']

then compile/install, no extra flags needed in my case:

pip install -r requirements-dev.txt # needed because see below
make  # needed because see below
pip install --force-reinstall .

Of course, plyvel has some ancient setup.py that doesn't even specify build dependencies or run Cython for you, so don't try to do like every other python package written since 2016 and just pip install . ... you have to run make...

@dhdaines
Copy link

dhdaines commented Sep 10, 2024

Sorry to pick on plyvel here, the real problem is that LevelDB made an ABI incompatible change in a minor version update (who does that???) google/leveldb#927

It might be possible to add a check to setup.py to add -fno-rtti if the LevelDB version is 1.23 or newer.

@wbolster
Copy link
Owner

wbolster commented Sep 10, 2024

Of course, plyvel has some ancient setup.py that doesn't even specify build dependencies or run Cython for you, so don't try to do like every other python package written since 2016 and just pip install . ... you have to run make...

just fyi this seemed sensible, at least in prehistoric times (12 years ago) 🧓🏼 </snark>

see this commit 66028d8

@dhdaines
Copy link

just fyi this seemed sensible, at least in prehistoric times (12 years ago) 🧓🏼 </snark>

Indeed, it definitely made sense in the stone age of Python packaging when there was no good solution for build dependencies!

@liviaerxin
Copy link

liviaerxin commented Sep 10, 2024

Hi there. If you need the already built binary plyvel packages for windows, Linux and macOS, please feel free to have a look at #152. It has built and packaged leveldb and snappy within it.

@jbothma
Copy link

jbothma commented Sep 27, 2024

The CFLAGS are not being passed into the build process

with Make also needed to pass the directories via setup.py. There's probably an easier way but this worked when I needed it.

-extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11']
+extra_compile_args = ['-Wall', '-g', '-x', 'c++', '-std=c++11', '-fno-rtti']

if platform.system() == 'Darwin':
    extra_compile_args += ['-stdlib=libc++']
@@ -25,6 +25,8 @@ def get_file_contents(filename):
        sources=['plyvel/_plyvel.cpp', 'plyvel/comparator.cpp'],
        libraries=['leveldb'],
        extra_compile_args=extra_compile_args,
+        include_dirs=['/opt/homebrew/Cellar/leveldb/1.23_1/include/'],
+        library_dirs=['/opt/homebrew/Cellar/leveldb/1.23_1/lib/'],
    )
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.