Calling Cython function from C code raises segmentation fault

I guess you are using Cython 0.29. Since 0.29, PEP-489 multi-phase module initialisation has been enabled for Python versions >=3.5. This means, using PyInit_XXX is no longer sufficient, as you are experiencing. Cython’s documentation suggest to use inittab mechanism, i.e. your main-function should look something like: #include “Python.h” #include “transcendentals.h” #include <math.h> #include <stdio.h> int … Read more

ImportError after cython embed

Usually, a Python-interpreter isn’t “standalone” and in order to work it needs its standard libraries (for example ctypes (compiled) or site.py (interpreted)) and also path to other site-packages (for example numpy) must be set. Albeit it is possible to make a Python-interpter fully standalone by freezing the py-modules and merging all c-extensions (see for example … Read more

calling dot products and linear algebra operations in Cython?

Calling BLAS bundled with Scipy is “fairly” straightforward, here’s one example for calling DGEMM to compute matrix multiplication: https://gist.github.com/pv/5437087 Note that BLAS and LAPACK expect all arrays to be Fortran-contiguous (modulo the lda/b/c parameters), hence order=”F” and double[::1,:] which are required for correct functioning. Computing inverses can be similarly done by applying the LAPACK function … Read more

Cython: “fatal error: numpy/arrayobject.h: No such file or directory”

In your setup.py, the Extension should have the argument include_dirs=[numpy.get_include()]. Also, you are missing np.import_array() in your code. — Example setup.py: from distutils.core import setup, Extension from Cython.Build import cythonize import numpy setup( ext_modules=[ Extension(“my_module”, [“my_module.c”], include_dirs=[numpy.get_include()]), ], ) # Or, if you use cythonize() to make the ext_modules list, # include_dirs can be passed … Read more

Compile main Python program using Cython

Contrary to what Adam Matan and others assert, you can in fact create a single executable binary file using Cython, from a pure Python (.py) file. Yes, Cython is intended to be used as stated – as a way of simplifying writing C/C++ extension modules for the CPython python runtime. But, as nudzo alludes to … Read more

Minimal set of files required to distribute an embed-Cython-compiled code and make it work on any machine

After further research (I tried in an empty Win 7 x64 bit VM, without any VCredist previously installed), it seems that these files are enough: the program itself, test.exe (produced by cython –embed and compilation with cl.exe) python37.dll python37.zip coming from packages named “Windows x86-64 embeddable zip file” in https://www.python.org/downloads/windows/ vcruntime140.dll, as mentioned in Can … Read more