3

I'm running clang on mac to compile a c file created by running a very simple program through cython, but the compiler always give me a "Python.h not found" fatal error. I've tried every solution I could find, reinstalling python 3.9, using the -I/path/to/headerfile method, and rewriting the include statement in the code to contain the full filepath, but nothing has worked. When I do include the full filepath, I get fatal error: 'cpython/initconfig.h' file not found. What could the issue possibly be, and how would I fix it? The program itself works fine in the standard python interpreter, pyinstaller, and nuitka.

James Bord
  • 31
  • 2
  • I can't help you for Mac, but on a linux system you'd need to install one of the `libpython-dev` packages (for 3.9, on Ubuntu/Debian, `libpython3.9-dev`) – Auspex Sep 07 '22 at 11:46

1 Answers1

1

Today I needed to embed Python into a C application developed on XCode with Clang compiler, and I've met the same problems and solved them. Let me share the tips:

1. Python not found error

You should install a Python framework to your MacOS, and attach it into Frameworks and Libraries project settings tab. Also, specify it's path in Framework Search Paths inside Build Settings tab if XCode hasn't done it automatically.

2. Undefined symbols / Implicit declaration errors

Verify you're using a modern version of Python framework. Versions prior to 3.6 had different ABI which leads to the mentioned errors.

3. cpython/initconfig.h file not found

Versions prior to ~3.9 had some header inclusion problem for the cpython/initconfig.h file (issues 40642, 39026).


Check the builds of Python that your OS currently has. I found Pythons installed in the following paths:

# Default 2.7 MacOSX installation is here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/

/Library/Frameworks/

Or install a recent Python version. I recommend using "universal binary" build, see the docs.

AivanF.
  • 1,134
  • 2
  • 23
  • 52