module faq.faq_cython#

Inheritance diagram of ensae_teaching_cs.faq.faq_cython

Short summary#

module ensae_teaching_cs.faq.faq_cython

Cython helpers

source on GitHub

Classes#

class

truncated documentation

CustomCythonError

raised by function compile_cython_single_script() when a script cannot be compiled with Cython

Functions#

function

truncated documentation

compile_cython_single_script

This function considers a script .pyx, writes the proper setup file, and compiles it.

Documentation#

Cython helpers

source on GitHub

exception ensae_teaching_cs.faq.faq_cython.CustomCythonError#

Bases : Exception

raised by function compile_cython_single_script when a script cannot be compiled with Cython

source on GitHub

ensae_teaching_cs.faq.faq_cython.compile_cython_single_script(script, skip_warn=True, fLOG=<function noLOG>)#

This function considers a script .pyx, writes the proper setup file, and compiles it.

Paramètres:
  • script – filename

  • skip_warn – skip warnings

  • fLOG – logging function

Renvoie:

output

The function applies the steps described in the basic tutorial The Basics of Cython. The function creates a setup.py in the same location and compiles it.

The compilation requires a compiler (not MinGW or Visual Studio (Community Edition)). If none was found, Python usually displays an error message like:

Unable to find vcvarsall.bat

You can also read this old blog post: Build a Python 64 bit extension on Windows about this file:: C:\Python35_x64\lib\distutils\msvc9compiler.py.

Compiler une function Cython ?

Cette fonction compile un script Cython. Cette extension permet d’implémenter des fonctions Python dans un pseudo-langage proche du C. Il faut suivre les instructions décrite dans le tutorial The Basics of Cython pour réussir à utiliser une fonction codée en Cython. C’est ce que fait la fonction compile_cython_single_script.

Etant donné que la partie en pseudo C est compilée afin de la rendre beaucoup plus rapide, la partie la plus difficile est généralement celle qui consiste à faire en sorte que l’interpréteur Python trouve le <b>bon</b> compilateur. Ce compilateur est nécessairement le même que celui utilisé pour compiler Python et celui-ci change à chaque version. Voir Compiling Python on Windows et faire attention à la version de Python que vous utilisez.

source on GitHub