dfm / python-fsps

Python bindings to Charlie Conroy's Flexible Stellar Population Synthesis (FSPS) Fortran code
https://python-fsps.readthedocs.io
MIT License
65 stars 38 forks source link

issue of installing&Changing libraries #241

Closed 0xygens closed 10 months ago

0xygens commented 10 months ago

Hi, I successfully installed python-fsps. And want to use PADOVA as the isochron library MILES as the stellar spectrum library, and follow the instructions to uninstall and change the library and reinstall. However, the installation was not successful. Could you provide some insights into this?Thanks for your guidance! The installation process and error information are as follows:

(pixedfit2) kongxiangming@agn:~/Downloads/fsps-3.2/src$ python -m pip install fsps
Collecting fsps
  Downloading fsps-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.4 kB)
Collecting numpy (from fsps)
  Using cached numpy-1.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
Downloading fsps-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 944.9 kB/s eta 0:00:00
Using cached numpy-1.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
Installing collected packages: numpy, fsps
Successfully installed fsps-0.4.5 numpy-1.26.1
(pixedfit2) kongxiangming@agn:~/Downloads/fsps-3.2/src$ pip uninstall fsps
Found existing installation: fsps 0.4.5
Uninstalling fsps-0.4.5:
  Would remove:
    /home/kongxiangming/.conda/envs/pixedfit2/lib/python3.10/site-packages/fsps-0.4.5.dist-info/*
    /home/kongxiangming/.conda/envs/pixedfit2/lib/python3.10/site-packages/fsps.libs/libgfortran-040039e1.so.5.0.0
    /home/kongxiangming/.conda/envs/pixedfit2/lib/python3.10/site-packages/fsps.libs/libquadmath-96973f99.so.0.0.0
    /home/kongxiangming/.conda/envs/pixedfit2/lib/python3.10/site-packages/fsps/*
Proceed (Y/n)? y
  Successfully uninstalled fsps-0.4.5
(pixedfit2) kongxiangming@agn:~/Downloads/fsps-3.2/src$ FFLAGS="-DMIST=0 -DPADOVA=1 -DMILES=1 -DBASEL=0" python -m pip install fsps --no-binary fsps
Collecting fsps
  Using cached fsps-0.4.5.tar.gz (54 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /home/kongxiangming/.conda/envs/pixedfit2/lib/python3.10/site-packages (from fsps) (1.26.1)
Building wheels for collected packages: fsps
  Building wheel for fsps (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for fsps (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [36 lines of output]
      *** scikit-build-core 0.5.1 using CMake 3.27.7 (wheel)
      *** Configuring CMake...
      2023-10-20 17:11:05,408 - scikit_build_core - WARNING - libdir/ldlibrary: /home/kongxiangming/.conda/envs/pixedfit2/lib/libpython3.10.a is not a real file!
      2023-10-20 17:11:05,408 - scikit_build_core - WARNING - Can't find a Python library, got libdir=/home/kongxiangming/.conda/envs/pixedfit2/lib, ldlibrary=libpython3.10.a, multiarch=x86_64-linux-gnu, masd=None
      loading initial cache file /tmp/tmpl_bb60du/build/CMakeInit.txt
      -- The C compiler identification is GNU 7.5.0
      -- The Fortran compiler identification is GNU 7.5.0
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /usr/bin/gcc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting Fortran compiler ABI info
      -- Detecting Fortran compiler ABI info - done
      -- Check for working Fortran compiler: /usr/bin/gfortran - skipped
      -- Found Python: /home/kongxiangming/.conda/envs/pixedfit2/bin/python (found version "3.10.13") found components: Interpreter Development.Module NumPy
      -- Configuring done (1.3s)
      CMake Error at /tmp/pip-build-env-rwru3336/normal/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPython/Support.cmake:4035 (add_library):
        Cannot find source file:

          /tmp/pip-install-puzkp0w9/fsps_8534c0ebc53f480ebd10627ff2cf21d0/src/fsps/libfsps/src/sps_vars.f90
      Call Stack (most recent call first):
        /tmp/pip-build-env-rwru3336/normal/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPython.cmake:635 (__Python_add_library)
        src/fsps/CMakeLists.txt:64 (python_add_library)

      CMake Error at /tmp/pip-build-env-rwru3336/normal/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPython/Support.cmake:4035 (add_library):
        No SOURCES given to target: _fsps
      Call Stack (most recent call first):
        /tmp/pip-build-env-rwru3336/normal/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPython.cmake:635 (__Python_add_library)
        src/fsps/CMakeLists.txt:64 (python_add_library)

      CMake Generate step failed.  Build files cannot be regenerated correctly.

      *** CMake configuration failed
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for fsps
Failed to build fsps
ERROR: Could not build wheels for fsps, which is required to install pyproject.toml-based projects
dfm commented 10 months ago

Thanks for the report! It looks like there's an issue with the most recent source distribution on PyPI and it doesn't include the FSPS source files that it should. We'll need to fix that, but in the meantime, you could install from source using the instructions here replacing the pip install line with:

- python -m pip install .
+ FFLAGS="-DMIST=0 -DPADOVA=1 -DMILES=1 -DBASEL=0" python -m pip install .
0xygens commented 10 months ago

Thank you for your prompt feedback! The fact that I didn't use this method is that I didn't understand. I have downloaded FSPS and made the environment variable point to the fsps installation folder next install python-fsps from PyPl. Does this method mean that I don't need to download FSPS again and just point the environment variable 'export SPS_HOME=$(pwd)/src/fsps/libfsps' to the python-fsps installation directory?

dfm commented 10 months ago

When you install python-fsps from source it also downloads a full copy of FSPS, so you can reuse that copy if you want, but it should also be fine to use your current SPS_HOME setup. That comment in the docs is a bit of an aside, you're not required to run the export SPS_HOME=$(pwd)/src/fsps/libfsps command.

0xygens commented 10 months ago

Thank you! Great and professional reply! My problem is solved and will close this issue.

0xygens commented 10 months ago

I turned this back on because one thing I found is that this doesn't work when SPS_HOME points to external FSPS. 'SPS_SETUP ERROR: xsp.lambda cannot be opened' like this test:

$python -c "import fsps; sp = fsps.StellarPopulation();  print(sp.libraries)"
SPS_SETUP ERROR: xsp.lambda cannot be opened

When SPS_HOME points to $(pwd)/src/fsps/libfsps.,it works again. I don't know why, but I think it's worth telling you. And then I'll close it again.

bd-j commented 10 months ago

Hi, you might try updating the external FSPS, as some of the data files were updated recently (which is captured by the FSPS submodule of python-FSPS, but must be explicitly updated in an external FSPS)

cd $SPS_HOME
git pull

Hope this helps.

0xygens commented 10 months ago

Thank you for your answer, which works well!