Complex Cython executable with f2py file module

I am trying to cythonize a python project found at https://pypi.python.org/packages/source/p/phaseshifts/phaseshifts-0.1.2-dev.zip with the ultimate goal of creating a standalone executable for the phsh.py module, Basic structure The project I want to implement has the following hierarchy:

phaseshifts/ __init__.py atorb.py conphas.py elements.py leed.py phsh.py lib/ __init__.py libphsh.pyd` 

Note. The libphsh.pyd module libphsh.pyd compiled using f2py .

I think my question is really divided into several parts:

1) . How can you use cython to create a standalone executable containing multiple .py[x]? files .py[x]? ? (e.g. using the --embed parameter for one module to embed a python interpreter)
2) If 1) it is possible, then .pyd or .so files can be compiled, and if so, how?

Any help from SO veterans would be most appreciated :-)

Edit

So far, the libphsh.f work has been to compile libphsh.f into a dll using gfortran -shared -o libphsh.dll libphsh.f and then edit the appropriate source files to load the library using ctypes . Then I used cython *.py to create the C source files of each python module, with the exception of phsh.py, where I used cython --embed phsh.py

Finally, I used GCC to compile the source and link to the python library, for example.

 gcc -o phsh.exe phsh.c __init__.c atorb.c conphas.c elements.c leed.c model.c \ -I"C:\Python27\include" -L"C:\Python27\libs" -lpython27 

However, when you run the compiled executable, the application ends the display of the message:

 This application has requested the Runtime to terminate it in an unusual way. Please contact the application support team for more information. 

Edit 2

Optional termination can be avoided by using g++ to compile the cpp souce file generated from:

 cython --cplus --embed phsh.py 

In fact, the points listed in the first edit bring a lot of effort and do not work, since the compiled executable is still trying to import each python module, so each module can be compiled, but the most important step is compile libphsh.f :

 f2py -m libphsh libphsh.f 

The next step is to try to automate this by installing the script ...

+6
source share

Source: https://habr.com/ru/post/970190/


All Articles