openalea-incubator / PyRATP

RATP: Radiation Absorption, Transpiration and Photosynthesis
Other
3 stars 5 forks source link

Installation with Python 3 and Fortran 90 #17

Open mwoussen opened 2 years ago

mwoussen commented 2 years ago

The file pyratp.pyd is not working on my configuration and doesn't seem to be built while installing the package with scons. My processor is a Intel i7-4800MQ 64 bits, with Windows 10. I installed a conda environment with Python 3.7 and the following packages :

Under this conda env, I did this modifications to adapt the code in Python 3 :

The command python setup.py install correctly installs the pakage but without rebuilding the pyratp.pyd file, only copying it.

The existing pyratp.pyd seems to be compiled for Python 2, so I tried to build it with f2py by typing the commands described in src/f90/SConscript :

  1. f2py -m pyratp --overwrite-signature -h [source_64bits]
  2. f2py -c --build-dir . --compiler=mingw32 --fcompiler=gnu95 [sources_64bits]

Where [sources_64bits] are the files written in src/f90/SConscript l.18-32 . The compile command (f2py -c) ends up with an error :

pyratpmodule.c: 3335: undefined reference to '__intrinsic_setjmpex' collect2.exe: error: ld returned 1 exit status

I also tried using a conda environnement with Python 2, but openalea.sconsx is no longer available for this version of Python which makes the python setup.py install command obsolete. Then, when I recreate the pyratp.pyf file, it calls unknown modules in the environnement so f2py -c can't build.

mwoussen commented 2 years ago

I managed to build the pyratp.pyd file, the procedure was :

1) f2py -m pyratp --overwrite-signature -h [source_64bits] 2) f2py -c --build-dir . --compiler=mingw32 --fcompiler=gnu95 [sources_64bits] 3) the process ends on the ld error as before 4) change #include <setjmp.h> to #include <setjmpex.h> in the src.win-amd64-3.7/pyratpmodule.c file 5) rerun f2py -c --build-dir . --compiler=mingw32 --fcompiler=gnu95 [sources_64bits], now it's building the file pyratp.src.win-amd64-3.7.pyd 6) run the last command of f2py -c ..., which is gfortran -Wall -g -shared .\Release\src.win-amd64-3.7\pyratpmodule.o .\Release\src.win-amd64-3.7\src.win-amd64-3.7\fortranobject.o .\Release\mod_[sources_64bits].o .\Release\src.win-amd64-3.7\pyratp-f2pywrappers.o -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0" -LC:\Users\mwoussen\Anaconda3\envs\ratp\libs -LC:\Users\mwoussen\Anaconda3\envs\ratp\PCBuild\amd64 -lpython37 -lgfortran -o .\pyratp.pyd, where ratp is the name of my conda env 7) Then, I copy pyratp.pyd among the Python files

pradal commented 2 years ago

Great! Thanks again for the tip. We will look at building a conda package from this work.

pradal commented 2 years ago

Use: https://numpy.org/devdocs/f2py/usage.html#automatic-extension-module-generation

pradal commented 8 months ago

In the branch meson, we will test the automatic build of PyRATP using meson with @thomasarsouze

pradal commented 5 months ago

@pellem Here is the next challenge. You can create a build.sh to run f2py in conda using the code in the Makefile

pradal commented 5 months ago

@pellem

  1. Read and understand meson.build
mamba install meson compilers
meson setup builddir
meson compile -C builddir
cd builddir

ipython 
import pyratp

Read https://numpy.org/doc/stable/f2py/buildtools/meson.html