O'Reilly logo

NumPy Cookbook - Second Edition by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a Hello World program

As is the tradition with programming languages, we will start with a Hello World example. Unlike Python, we need to compile Cython code. We start with a .pyx file, from which we will generate C code. This .c file can be compiled and then imported into a Python program.

How to do it...

This section describes how to build a Cython Hello World program:

  1. First, write some pretty simple code that prints Hello World. This is just normal Python code, but the file has the pyx extension:
    def say_hello():
      print "Hello World!"
  2. Create a file named setup.py to help build the Cython code:
    from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension("hello", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required