I'm working on project where I am using Python/C API and C++. C++ is used for most part of application, mainly for gui (wxWidgets), while Python is used for calculations on large data sets, e.g. from files. I'm doing it in Visual Studio and when I run the project in IDE everything works fine, like I want it to. Also, the exe file that is created during the launch of the project in the visual studio, when it is in the same folder with the python .py file, also works as it should be. But what I want to achieve is a complete application contained in one exe.
While searching for a solution, I found various possibilities to create an exe from a python file. For example, PyInstaller which I tested for a simple "hello world" python file and it works. However, I don't know and can't find a solution how to combine the exe created in visual with a python file.
I hope that someone has done a similar thing before and I can find help here because I'm already losing my mind on it.
And, above all, is it possible?
#include <Python.h>#include <iostream>
int main(){ PyObject *pModule, *pClass, *pArgs, *pInstance, *pMethod;
Py_Initialize();
std::cout << "FirstCPPString" << std::endl;
pModule = PyImport_ImportModule("PythonApplication1"); pClass = PyObject_GetAttrString(pModule, "Importer"); pArgs = Py_BuildValue("()"); pInstance = PyEval_CallObject(pClass, pArgs);
Py_DECREF(pModule); Py_DECREF(pClass); Py_DECREF(pArgs);
pMethod = PyObject_GetAttrString(pInstance,"start"); pArgs = Py_BuildValue("()");
PyEval_CallObject(pMethod, pArgs);
Py_DECREF(pInstance); Py_DECREF(pMethod); Py_DECREF(pArgs); Py_Finalize(); std::cout << "SecondCPPString" << std::endl;}print ('FirstPythonString')
class Importer: def start(self): print('SecondPythonString')And after starting project in visual, I get exe file, as a result of compile. But it's only exe with cpp file. Without .py file placed in the same folder, I got an error after running exe. And what I want, is, let's say, combine existing exe with .py file to one exe. I hope I said it clear.
Ahh your embedding Python into C++. I’ve never done that so I probably can’t help much. I imagine your C++ program needs to be able to find python3.dll and all its dependents so it needs to be in either your PATH or your current working directory. And it will also need PythonApplication1.py to be separated from the PyInstaller exe.
If you PyInstaller PythonApplication1.py, compile your C++ code, then copy PythonApplication1.py and cppFile.exe into dist/PythonApplication1/. Then launch `cppFile.exe`. Don’t try to use --onefile with PyInstaller yet - I can show you how to turn it into a single file after we’ve got it working as a bundle first.
Ahh your embedding Python into C++. I’ve never done that so I probably can’t help much. I imagine your C++ program needs to be able to find
python3.dlland all its dependents so it needs to be in either yourPATHor your current working directory. And it will also needPythonApplication1.pyto be separated from the PyInstaller exe.If you
PyInstaller PythonApplication1.py, compile your C++ code, then copyPythonApplication1.pyandcppFile.exeintodist/PythonApplication1/. Then launch `cppFile.exe`. Don’t try to use--onefilewith PyInstaller yet - I can show you how to turn it into a single file after we’ve got it working as a bundle first.
--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/ace71e6b-cb01-4691-8b01-2eb3e6356a4fn%40googlegroups.com.
Ahh your embedding Python into C++. I’ve never done that so I probably can’t help much. I imagine your C++ program needs to be able to find
python3.dlland all its dependents so it needs to be in either yourPATHor your current working directory. And it will also needPythonApplication1.pyto be separated from the PyInstaller exe.If you
PyInstaller PythonApplication1.py, compile your C++ code, then copyPythonApplication1.pyandcppFile.exeintodist/PythonApplication1/. Then launch `cppFile.exe`. Don’t try to use--onefilewith PyInstaller yet - I can show you how to turn it into a single file after we’ve got it working as a bundle first.
--
Thanks for all the answers. I think I got a lesson for the future, to firstly check if something is possible and then do it. :) I'll check nuitka and shedskin,
but I wonder if it will not be easier to rewrite python functions to c++ and stay with c++ only.
--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/3b6107cd-0f9f-454e-82f4-d3c6c3de1b5do%40googlegroups.com.
At this point you’ve done the opposite of what most folks do— written the non-computationally intensive GUI in C++, and the computational bits in Python :-)