Installing Cython

Many scientific Python distributions, such as Anaconda[Anaconda],Enthought Canopy[Canopy], and Sage[Sage],bundle Cython and no setup is needed. Note however that if yourdistribution ships a version of Cython which is too old you can stilluse the instructions below to update Cython.

Unlike most Python software, Cython requires a C compiler to bepresent on the system. The details of getting a C compiler variesaccording to the system used:

  • Linux The GNU C Compiler (gcc) is usually present, or easilyavailable through the package system. On Ubuntu or Debian, forinstance, it is part of thebuild-essential package. Next to aC compiler, Cython requires the Python header files. On Ubuntu orDebian, the commandsudoapt-getinstallbuild-essentialpython3-devwill fetch everything you need.

  • Mac OS X To retrieve gcc, one option is to install Apple’sXCode, which can be retrieved from the Mac OS X’s install DVDs orfromhttps://developer.apple.com/.

  • Windows The CPython project recommends building extension modules(including Cython modules) with the same compiler that Python wasbuilt with. This is usually a specific version of Microsoft VisualC/C++ (MSVC) - seehttps://wiki.python.org/moin/WindowsCompilers.MSVC is the only compiler that Cython is currently tested with onWindows. If you’re having difficulty making setuptools detectMSVC thenPyMSVCaims to solve this.

    A possible alternative is the open source MinGW (aWindows distribution of gcc). See the appendix for instructions forsetting up MinGW manually. Enthought Canopy and Python(x,y) bundleMinGW, but some of the configuration steps in the appendix mightstill be necessary.

The simplest way of installing Cython is by usingpip:

pipinstallCython

On platforms that are covered by one of the binary wheel packages provided on PyPI,this will install an accelerated wheel which contains some Cython compiled modules.Other platforms will use pure Python wheels that install quickly but run somewhatslower, which is still well adapted for one-time builds e.g. in CI build servers.

For installations on systems where Cython is executed a lot, it is worth checking thatthe installation uses a binary module, or otherwise to build a binary wheel locally.

The newest Cython release can always be downloaded fromhttps://cython.org/. Unpack the tarball or zip file, enter thedirectory, and then run:

pipinstall.

For one-time installations from a Cython source checkout, it is substantiallyfaster than a full binary build to just install the uncompiled (slower) versionof Cython with something like

NO_CYTHON_COMPILE=truepipinstall.