lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
230 stars 285 forks source link

problem with installing the python wrapper #356

Open xiaohanzai opened 4 years ago

xiaohanzai commented 4 years ago

I use a macbook pro with python 3.8.3 installed via anaconda. The C compilation is fine with "make", and the python compilation didn't give an error in this step. But when trying "import classy", there is always an error saying

Traceback (most recent call last): File "", line 1, in ImportError: dlopen(/Users/xiaohan/.local/lib/python3.8/site-packages/classy.cpython-38-darwin.so, 2): Symbol not found: _GOMP_loop_nonmonotonic_dynamic_next Referenced from: /Users/xiaohan/.local/lib/python3.8/site-packages/classy.cpython-38-darwin.so Expected in: flat namespace in /Users/xiaohan/.local/lib/python3.8/site-packages/classy.cpython-38-darwin.so

I can't find a solution on google. This is my python info:

Python 3.8.3 (default, Jul 2 2020, 11:26:31) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin

This is gcc --version:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.3 (clang-1103.0.32.62) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I've tried compiling with another gcc that I installed with homebrew but it gives the same error when importing classy.

When trying to install on a linux machine, I get an error when compiling the python wrapper saying ld -lmvec is not found. There is also no solution on google about this...

losvaldote commented 3 years ago

Hi. I think this has to do with compilers and lgomp library compatibility. I've had similar problems on Mac, in fact I once got the same "_GOMP_loop_nonmonotonic_dynamic_next" error. What I did to be able to use classy was install gcc-10 from homebrew and modified line 20 of the Makefile. I put CC = gcc-10 and I commented the other lines # CC = icc and #CC = pgcc.

Following the instructions given in https://github.com/lesgourg/class_public/issues/349:

I modified line 41 of setup.py file in python folder: extra_link_args = ['- lgomp', '-Wl, -rpath, / usr / local / opt / gcc / lib / gcc / 10 /']). This is the direction of the homebrew gcc-10 (I think here is the compilers problem but this worked for me).

You must update Xcode. On the other hand, I used a conda environment for python 2.7 but I think it may be work for you. With this I had no problem with classy.

Greetings. LO.

lingyuanji commented 3 years ago

I am having the exact same problem as @xiaohanzai. The problem persists after implementing the solution suggested by @losvaldote and #349.

My system information:

ThomasTram commented 3 years ago

Hi, what is the output of

python -c 'import classy; print(classy.__path__)'

? Sometimes a classy version is installed in ".local" and takes precedence from the one installed in Anaconda site packages. Try removing the local version in this case.

Cheers, Thomas

lingyuanji commented 3 years ago

For me python -c 'import classy; print(classy.__path__)' still outputs the original error mentioned by @xiaohanzai. It seems that the package was not loaded in the first place.

But I was able to make it work after removing ~/.local/lib/python2.7/site-packages/classy.so, or removing ~/.local/lib/python2.7/site-packages from sys.path in python. I believe they have the same effect.