3

I am to developing an SDK for my internship but there a smaller steps which need to be completed first, one of which involves being able to create an executable.

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

d.c:4:20: fatal error: Python.h: No such file or directory compilation terminated.

I've looked in /usr/include/python2.7 and Python.h does exist but for some reason nothing is happening? I've downloaded the lastest version of python-dev as some threads have suggested yet nothing seems to be solving the problem. Any help at all would be brilliant.

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

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

cython test.py --embed

Once the test.c file has been generated I then typed:

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

This then created an executable called test which could be than ran. I hope this helps anyone else with this problem.

Community
  • 1
  • 1
  • 1
    search for Python.h in your system. it may not be located in `/usr/include/python2.7` run this command `sudo find / -name Python.h` you will get list of paths where `Python.h` file exists . include the right version of python file path while `gcc compile` – Mr. A Jul 06 '15 at 05:58
  • Would you mind to post your solution as an answer and accept it? This would help other programmers with the same problem finding it and this question would no longer show up as unsolved. Thanks :) – m00am Sep 15 '15 at 11:57
  • @Mr.A in EDIT 1 I posted the commands I typed to make it work in the end :) –  Sep 15 '15 at 12:05

0 Answers0