LSSTDESC / CCL

DESC Core Cosmology Library: cosmology routines with validated numerical accuracy
BSD 3-Clause "New" or "Revised" License
145 stars 64 forks source link

Error when importing CCL - ccllib circular import (developer instalation) #1174

Open luigilcsilva opened 5 months ago

luigilcsilva commented 5 months ago

Hi, everyone!

I recently updated CCL (I am using the developer instalation), but now I am getting an error when I try to import the library. I'll leave the print below. If anyone can help me, I would be very grateful!

error-importing-CCL

luigilcsilva commented 1 month ago

I made a few attempts here and ultimately the issue was fixed.

Activate virtual environment

source /home/luigi/.conda/envs/cosmology/bin/activate

Or, simply

conda activate cosmology

Dependency install

pip install numpy pip install cmake

Tried to run "python setup.py build" in CCL directory, but I got an error message, so I followed the steps below.

Changed the /home/luigi/cosmology/CCL/cmake/Modules/FindNumPy.cmake file content to (probably it is a good idea to make a backup of the original file):

echo 'find_package(PythonInterp REQUIRED) execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.path[0])" OUTPUT_VARIABLE NumPy_PATH OUTPUT_STRIP_TRAILING_WHITESPACE )

set(NumPy_INCLUDE_DIR "${NumPy_PATH}/core/include") set(NumPy_FOUND TRUE)' > ~/cosmology/CCL/cmake/Modules/FindNumPy.cmake

Defined the "build" directory permissions:

sudo chmod -R 777 ~/cosmology/CCL/build

Edited the file CMakeLists.txt and added the following lines (/home/luigi/cosmology/CCL/CmakeLists.txt) (probably it is a good idea to make a backup of the original file).

echo 'cmake_minimum_required(VERSION 3.5) cmake_policy(SET CMP0078 OLD) cmake_policy(SET CMP0086 OLD) cmake_policy(SET CMP0148 OLD)' | cat - ~/cosmology/CCL/CMakeLists.txt > temp && mv temp ~/cosmology/CCL/CMakeLists.txt

Remove all the files from the build directory:

rm -rf ~/cosmology/CCL/build/*

Get the path of 'arrayobject.h' file:

python -c "import numpy; print(numpy.get_include())"

Edited again the CMakeLists.txt file, including the path in it:

include_directories(/home/luigi/.conda/envs/cosmology/lib/python3.12/site-packages/numpy/core/include)

Configured again:

cd ~/cosmology/CCL/build rm -rf * cmake -DPYTHON_EXECUTABLE=/home/luigi/.conda/envs/cosmology/bin/python .. cd ~/cosmology/CCL python setup.py build

The above steps were actually performed for a sequence of problems that appeared. You may not need all of them to solve your problem.