Including Python headers in distribution?

The Python environment of the official binary distributions don’t contain all the necessary development files for Python to provide a standalone SDK. For example, with 2.81 on Linux, these are the only Python related things included:

  • 2.81/python/bin/python3.7m - standalone interpreter. Importing bpy won’t work, but it can be used to install modules through pip in the Blender dir after running with -m ensurepip first.
  • 2.81/python/include/python3.7m/pyconfig.h - build configuration of the python environment included in the Blender executable
  • 2.81/python/lib/python3.7 - Standard library of Python modules and packages, plus a few extra ones like numpy and requests
  • 2.81/python/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a - Static library version of the Python routines. The blender executable itself has been statically linked to this library (I assume).

I don’t know if the above situation is different on macOS or Windows, but I would be surprised if this is the case. This also seems to have been what is included in the official binaries since at least 2.79a.

The above does not constitute a full SDK with which Python extensions in C can be built (which some addons use, including one of my own), as the necessary Python headers are not included. My Arch Linux system recently switched to Python 3.8.0 as the default version, while Blender 2.81 uses 3.7.4, so the right Python headers are no longer available by default. So I’m figuring out what the best way is to deal with this.

I could extract the Python 3.7.4 sources somewhere, build a binary version using static linking and then use that to run python374 setup.py on my extension, hoping that this will work. It might, I haven’t tried yet.

But I would much rather use Blender’s included python37m binary, run that on setup.py, and have it build and install my extension, as that should make sure it compiles things in the correct way, matching whatever configuration was used for the built-in Python interpreter in Blender. But this is currently not feasible as not all the development files are there. So I’m wondering why this is the case? Is it a concious decision to leave out SDK-like files that only a few people would use? Or are there technical issues with distributing a full SDK?

Replying to myself with some extra information :slight_smile:

Building Python 3.7.4 separately and then using that python binary to build the extension works. And it can then also be used in Blender.

Bumping this thread. Is there a good reason why the python SDK is not included in the Blender distribution?