Search code examples
c++visual-studiodeploymentrelease

How to embed python into C++ aplication and then deploy/release?


I am currently working on a C++ gui application. The application uses the Python/C API to call some python scripts. The scripts are located in the solution directory, and I call them by simply providing the path. This is currently working fine while debugging the application or even running the generated .exe file, but I am wondering how this could work if I want to release and distribute the application onto a different computer for someone to use. How can these scripts be deployed with the application?

I also have a .ttf font file with the same situation. How can this resource file be deployed with the application?

In other words, I want to deploy/release a C++ application with the scripts and resource files.

FYI: the C++ application is a Visual Studio project.

Thanks for the help in advance, and let me know if any more information is needed!

Update:

I just wanted to clear up the way my project is working currently:

PyObject* pArgs = PyTuple_New(5); // I setup the arguments the python function needs
PyImport_ImportModule("requests"); // imports...
// make python call
PyObject* pResult = PyObject_CallObject(pFunc, pArgs);

So this is (for the most part) how I call the scripts with the C++ source code. The scripts are located in a folder that is located in the solution directory.

I hope this explains my problem a little better.

Update:

Just another little update... Using some answers to other similar questions got me to the following point:

I need to obtain a python library, compile and link it with my C++ application, and then bundle the dependencies with the application (How to distribute C++ application which calls Python?)

So I guess my question is now shifting to how I would be able to get this done. What are the specific steps to do this? I also got a link (https://docs.python.org/3.5/using/windows.html#embedded-distribution) to an embedded distribution of a python environment (maybe this should somehow be used?). Also, I am able to statically link python into the application. I just don't know how to bundle and deploy the scripts I created and use in the application.


Solution

  • PyImport_ImportModule("requests")
    

    The parameter is "requests". Put the py file aside exe file when distributing.