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

Python bindings problem on Mac m2 Ventura #29

Closed
henshs opened this issue May 19, 2023 · 6 comments
Closed

Python bindings problem on Mac m2 Ventura #29

henshs opened this issue May 19, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@henshs
Copy link

henshs commented May 19, 2023

I am using Mac M2 Ventura and trying to install RePrimAnd with its Python interface. "pip install pyreprimand" did not work. When trying to build "meson mbuild --buildtype=release", it gave error that 'boost is not found'. It was solved by ''export BOOST_ROOT=/opt/homebrew/Cellar/boost/1.81.0_1/".

Then, I have sucessfully built and installed the C++ library of RePrimAnd using the source code. I could not install the Python interface, following

"cd bindings/python"
"pip install ."

It gives errors related to pybind11. I am using conda environment and as suggested I had installed numpy and pybind11 using conda beforehand. I have attached errors and output file herewith. I would be glad if this problem could be solved.

error.txt
output.txt

@wokast
Copy link
Owner

wokast commented May 19, 2023

Thanks for reporting.

Those are two separate issues

  1. pip install pyreprimand did not work
    The package on pypi is called just reprimand, not pyreprimand, so the command should be pip install reprimand. However, prebuild python wheels for MacOS are currently not supported since Apple makes that deliberately difficult for Open Source software. This will probably not be fixed any time soon, but a conda package is already in preparation which would then also work on MacOS.
  2. Building Python bindings from source failing
    The errors indicate that the module is compiled using an ancient C++ standard before C++11. The setup script does not specify the language version (this is indeed a bug) but only very old versions of gcc do not at least use C++11 as default.

To further diagnose 2) please

  1. provide the gcc version used for the failed build
  2. try CXXFLAGS=-std=c++11 CFLAGS=-std=c++11 pip install .
  3. try installing gcc using conda in the same environment an run pip install .

@wokast wokast self-assigned this May 19, 2023
@wokast wokast added the bug Something isn't working label May 19, 2023
@henshs
Copy link
Author

henshs commented May 19, 2023

  1. As I have seen in a Q&A in stack that the Apple places a gcc binary in /usr/bin/gcc but it just runs clang LLVM. This gcc was used for the failed build. The Apple clang version is 14.0.0 (clang-1400.0.29.202). I just see the clang version when I run gcc --version
  2. After trying CXXFLAGS=-std=c++11 CFLAGS=-std=c++11 pip install ., the errors related to compiler is disappeared. But it gives an error related to boost library not found. I can not understand why there is this error even after setting export BOOST_ROOT=/opt/homebrew/Cellar/boost/1.81.0_1/ while the library was built. I am thinking if I should add the path of include and lib directory of boost like CXXFLAGS=-std=c++11 CFLAGS=-std=c++11 -I/opt/homebrew/Cellar/boost/1.81.0_1/include/ -L/opt/homebrew/Cellar/boost/1.81.0_1/lib/ pip install ..
  3. The last error does not seem a compiler error (right ?), so I have not yet tried to install gcc using conda and run pip install .

The standard output and error are attached herewith.

output1.txt
error1.txt

@wokast
Copy link
Owner

wokast commented May 19, 2023

Interesting. Clang with default options usually accepts compiles C++11 code, Apple must have messed with that. In any case, the build script should specify the standard to avoid such problems. This will be fixed in the next release. For now, the workaround with CXXFLAGS=-std=c++11 seems to work.

Regarding the BOOST problem, I note that the Python bindings setup.py has no logic to search for library include files outside the system include path, as this is unreliable and ambiguous (e.g. if installed in several locations). It also ignores library-specific environment variables such as BOOST_ROOT. This differs from building the C++ library itself, because the meson build system does much more effort than the Python tools. Building the Python bindings could probably be made more user-friendly. For the time being, one has to provide the include path for libraries in nonstandard locations via CPPFLAGS=-I<path>. For boost, it should not be required to provide a libdir (i.e. the -L option) since reprimand only uses header-only boost components.

@henshs
Copy link
Author

henshs commented May 20, 2023

Understand. Indeed building Python binding worked successfully after I tried CXXFLAGS=-std=c++11 CFLAGS=-std=c++11 CPPFLAGS=-I/opt/homebrew/opt/boost/include/ pip install .. I have checked if RePrimAnd is working properly with its Python interface by trying the example "/repository/examples/pwpoly_TOV.py" and it generated a pdf of two plots (namely, 'mass vs radius' and 'lambda vs compactness').

I also compiled successfully "/repository/examples/minimal_tov.cc" by g++ -lRePrimAnd -I/opt/homebrew/opt/boost/include --std=c++11 minimal_tov.cc and it generated "a.out". When I tried ./a.out it gave an error

"dyld[74642]: symbol not found in flat namespace '_cblas_caxpy'
zsh: abort ./a.out"

I could not find the root of this problem.

Also, I was trying to run unit tests as it is suggested in the RePrimAnd installation guide page meson configure -Dbuild_tests=true. It showed some options in the terminal but I could not find what option to choose and how. I entered "q" to quit and then tried ninja test which gives an error

"ninja: error: loading 'build.ninja': No such file or directory"

I would be glad if any way out could be suggested.

As it was written above that the package on pypi is called just reprimand, not pyreprimand, so the command should be pip install reprimand but it is pip install pyreprimand in the RePrimAnd installation guide as described in https://www.atlas.aei.uni-hannover.de/holohome/wolfgang.kastaun/doc/reprimand/latest/installing.html and also in https://pypi.org/project/RePrimAnd/. I would like to bring your attanetion to that also.

@henshs henshs changed the title Python Bindings problem on Mac m2 Ventura Python bindings problem on Mac m2 Ventura May 20, 2023
@wokast
Copy link
Owner

wokast commented May 20, 2023

It seems that the original issue is understood. Please open two new tickets for the new problems of running the example and building the tests, and provide a sequence of commands to reproduce the problem starting from a fresh checkout.

I have opened another issue #30 about the typo in the documentation. Note however that the link you pasted above is outdated (I will replace that by a redirection). The official online documentation is the one linked from the github project page:
https://wokast.github.io/RePrimAnd/index.html

@wokast
Copy link
Owner

wokast commented Jun 1, 2023

Closing this after open questions were resolved in issues #31 and #32

@wokast wokast closed this as completed Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants