Try statement in Cython for cimport (for use with mpi4py)
问题 Is there a way to have the equivalent of the Python try statement in Cython for the cimport? Something like that: try: cimport something except ImportError: pass I would need this to write a Cython extension that can be compiled with or without mpi4py. This is very standard in compiled languages where the mpi commands can be put between #ifdef and #endif preprocessor directives. How can we obtain the same result in Cython? I tried this but it does not work: try: from mpi4py import MPI from