Turn Cython code into executable "Python.h: No such file or directory

I have to develop an SDK for my internship, but there are smaller steps to follow first, one of which is the ability to create an executable.

We are using Python, so my employer wants it to be converted to C code via Cython and then turned into an executable file by compiling it as if it were a regular C program using gcc. So getting the C file is not a problem, it's just the next step. Every time I try to compile the C file into an executable, the following error occurs:

dc: 4:20: fatal error: Python.h: no such file or directory compilation completed.

I looked in / usr / include / python 2.7 and Python.h exists but for some reason nothing happens? I downloaded the latest python-dev as some threads suggested, but nothing seems to solve the problem. Any help whatsoever would be brilliant.

EDIT 1: I found the solution here, "Compile a main program with Cython"

Basically the problem was that when compiling with Cython, I needed to add the -embed tag at the end, so let's say I have a test.py file, then first type:

cython test.py --embed

Once the test.c file was generated, I typed:

gcc -Os -I /usr/include/python2.7 -o test test.c -lpython2.7

An executable file called test was then created that could be run. Hope this helps someone else with this problem.

+3


source to share





All Articles