5

I am trying to compile a simple "Hello, World!" in Cython. In a file I have:

print("Hello, World!")

I run:

cython hello_world.pyx

To get the hello_world.c file. I then try:

gcc -c hello_world.c

Which gives the error:

fatal error: 'Python.h' file not found

Then I tried this:

gcc -c hello_world.c -framework Python

Didn't work. I had changed include "Python.h" to <Python/Python.h> and got a different error:

fatal error: 'longintrepr.h' file not found

Regardless, I want to use Python3, not the Python Apple ships with, but I am unable to figure out where the Python3 development headers are located.

Ultimately, I want to be able to compile hello_world.c so that it works in a Python3 interpreter.

(I am using brew's python3.5.2_1, if that helps.)

Community
  • 1
  • 1
Dair
  • 15,910
  • 9
  • 62
  • 107
  • Have you tried simply `whereis` the python executable you are using? IIRC the path is something along the lines of `/usr/local/bin` and brew installs headers in `/usr/local/include`. Unfortunately I don't have a mac anymore so I can't check – UnholySheep Sep 11 '16 at 21:18
  • On Linux you need to install python-dev. Perhaps the same is required with brew. – zmbq Sep 11 '16 at 21:19
  • check if it here /usr/local/Cellar/python//Frameworks/Python.framework/Versions//include/python/Python.h – sr3z Sep 11 '16 at 21:26
  • 1
    @sr3z: Not quite but close enough for me to figure it out! Thanks! Pretty much off by the letter `m` lol. – Dair Sep 11 '16 at 21:43
  • The linux 'find' command is great for... finding things. It's kind of complicated, but it's well worth the trouble to learn how it works. – Rex D Sep 12 '16 at 00:24

2 Answers2

2

Currently is /usr/local/Frameworks/Python.framework/Headers.

WeZZard
  • 3,536
  • 1
  • 23
  • 26
  • For anyone else who lands here the answer is correct but just be aware the path above is a symlink to another directory – Anon Sep 13 '18 at 13:42
1

Going off from @sr3z's comment, doing:

gcc -c random_sum.c -I/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/include/python3.5m

Creates random_sum.o.

Dair
  • 15,910
  • 9
  • 62
  • 107