Search code examples
pythoncdlldistribution

How to create an application which embeds and runs Python code without local Python installation?


Hello fellow software developers.

I want to distribute a C program which is scriptable by embedding the Python interpreter.
The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding.

I'm looking for a solution where I distribute only the following components:

  • my program executable and its libraries
  • the Python library (dll/so)
  • a ZIP-file containing all necessary Python modules and libraries.

How can I accomplish this? Is there a step-by-step recipe for that?

The solution should be suitable for both Windows and Linux.

Thanks in advance.


Solution

  • Have you looked at Python's official documentation : Embedding Python into another application?

    There's also this really nice PDF by IBM : Embed Python scripting in C application.

    You should be able to do what you want using those two resources.