Skip to content
Advertisement

Getting started with cython on mac os

I wrote a simple program in python:

JavaScript

Then I execute this:

JavaScript

It was generated a file: main.c And then I tried this:

JavaScript

And I have an error:

JavaScript

How to compile python to c ? How to get started with cython with xcode on mac ?

Advertisement

Answer

You have to tell the gcc compiler where is the pyconfig.h file on your system using the -I flag. You can find it using the find program.

A simpler way to compile the module is using a setup.py module. Cython provides a cythonize function that starts this process for a .pyx module.

Another point you are missing is that Cython files usually define helper functions to be used from a main Python module.

Suppose you have the following setup as for dirs and files:

JavaScript

The contents of the setup.py are

JavaScript

The contents of the split_urls.pyx file are

JavaScript

And it is the main.py module which uses the defined Cython function:

JavaScript

Compile the Cython module by issuing:

JavaScript

And check that your main module is doing what it is supposed to do:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement