dfm / python-fsps

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

Installation on Windows 11 Issue: "Invalid Escape Character" with pip Install #259

Closed gregorycorcoran closed 5 months ago

gregorycorcoran commented 6 months ago

Hi, I was trying to install during the weekend using pip and ran into an issue I could not think of a solution for. After running the pip install command while in a conda virtual environment the output was as follows:

(prospect) C:\Users\gjc10>pip install fsps
Collecting fsps
Using cached fsps-0.4.6.tar.gz (120 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 c:\users\gjc10\anaconda3\envs\prospect\lib\site-packages (from fsps) (1.26.3)
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
╰─> [33 lines of output]
*** scikit-build-core 0.7.1 using CMake 3.26.4 (wheel)
*** Configuring CMake...
2024-01-21 16:49:29,903 - scikit_build_core - WARNING - Can't find a Python library, got libdir=None, ldlibrary=None, multiarch=None, masd=None
loading initial cache file C:\Users\gjc10\AppData\Local\Temp\tmpg3zvtq77\build\CMakeInit.txt
-- Building for: Ninja
-- The C compiler identification is GNU 13.2.0
-- The Fortran compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/cygwin64/bin/gcc.exe - 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: C:/cygwin64/bin/gfortran.exe - skipped
-- Found Python: C:\Users\gjc10\anaconda3\envs\prospect\python.exe (found version "3.12.1") found components: Interpreter Development.Module NumPy
CMake Error at C:/Users/gjc10/anaconda3/envs/prospect/Library/share/cmake-3.26/Modules/FindPython.cmake:641 (__Python_add_library):
Syntax error in cmake code at
    C:/Users/gjc10/anaconda3/envs/prospect/Library/share/cmake-3.26/Modules/FindPython.cmake:641

    when parsing string

      _fsps;MODULE;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/fsps.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sps_vars.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sps_utils.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/add_agb_dust.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/add_bs.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/add_dust.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/add_nebular.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/add_remnants.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/add_xrb.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/agn_dust.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/attn_curve.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/compsp.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/csp_gen.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/funcint.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/get_lumdist.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/get_tuniv.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/getindx.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/getmags.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/getspec.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/igm_absorb.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/imf.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/imf_weight.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/intsfwght.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/linterp.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/linterparr.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/locate.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/mod_gb.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/mod_hb.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/pz_convol.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sbf.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/setup_tabular_sfh.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sfh_weight.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sfhinfo.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sfhlimit.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sfhstat.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/smoothspec.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/spec_bin.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/sps_setup.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/ssp_gen.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/tsum.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/vacairconv.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/write_isochrone.f90;C:/Users/gjc10/AppData/Local/Temp/pip-install-7tgfgsn1/fsps_14704cb4831240a38e1855474ac3f752/src/fsps/libfsps/src/ztinterp.f90;C:/Users/gjc10/AppData/Local/Temp/tmpg3zvtq77/build/src/fsps/_fspsmodule.c;C:/Users/gjc10/AppData/Local/Temp/tmpg3zvtq77/build/src/fsps/_fsps-f2pywrappers2.f90;C:\\Users\\gjc10\\AppData\\Local\\Temp\\pip-build-env-_096e5eh\\overlay\\Lib\\site-packages\\numpy\\f2py\\src/fortranobject.c;WITH_SOABI

    Invalid character escape '\\U'.
  Call Stack (most recent call first):
    src/fsps/CMakeLists.txt:69 (python_add_library)

  -- Configuring incomplete, errors occurred!

  *** CMake configuration failed
  [end of output]

From this error message it appears that for some reason the file path reverted to the standard windows method of using back slashes part way through. I understand that recently there has been a fix to have this compile to windows so I would love to know if there is a solution to this error, outside of using WSL.

dfm commented 5 months ago

Thanks for raising this issue! I'm definitely not a Windows expert, but I think the issue is coming from here:

https://github.com/dfm/python-fsps/blob/e97c51d415fc27f7c5af1994a2af32598753a2a0/tools/f2py_include.py#L10

That script gets executed by CMake to find the appropriate numpy include directories, and I think CMake needs the output to be in POSIX rather than Windows native format. I think it should be possible to fix that behavior by updating the linked line to:

-     print(os.path.join(os.path.dirname(numpy.f2py.__file__), "src"))
+     print(os.path.normpath(os.path.join(os.path.dirname(numpy.f2py.__file__), "src")))

Can you try installing from source (following these instructions) after updating that line?