Solved How to use/execute a Python script inside QtCreator C++ project
-
@Chris-Kawa
Haha, sadly its not far from common truth.We use autocad and the drawing are also show to potential buyers.
I have shown the sales persons how to export to pdf to send via mail.The marketing boss however, didn't feel like exporting - so he send the native format to a client. The client cannot watch it (surprice) and ask him how to open it.
The boss ask me and i tell client we thus this autodesk viewer. DWG TrueView (720 MB) The client tries to install it, but being on Win 7 - it wants all .NET runtimes
updated and he end up calling his IT person.
The TrueView fails to install several times for him and he ask the client if we can do something else. The Client ask the Boss and he ask me to call the clients IT dude.
The IT dude ask how we can solve it and I say just "a moment" and then export the
drawing to PDF and send it.... -
@Niagarer
Well it depends how much of python you need/use. If the trade off in deployment are worth it.That said, there is
https://www.python.org/ftp/python/3.6.3/python-3.6.3-embed-win32.zip
Which can run from a local folder as far as i can see.
The docs says
"Windows Users: There are redistributable zip files containing the Windows builds, making it easy to redistribute Python as part of another software package. Please see the documentation regarding Embedded Distribution for more information."But if your app is to run on say Mac,Linux AND windows, i would not myself go down the route of including/needing python as its bound to give issues.
However, if only for windows, then this new feature in 3.5
https://docs.python.org/3.6/using/windows.html#embedded-distribution
is ment for your scenario and makes it far less involved mixing c++/python
on windows. -
@mrjj Haha, well I didn't just make it up. It's a very common scenario. Trading hours of users time/money/resources to workaround a minor development inconvenience.
As for the embedded solution. It is a solution but I don't like it personally. Just out of curiosity I searched for python on my system and I found I have 23 copies of the interpreter, installed along various software :/ That's just awful.
I know it's against the tide these days but I treat python as a development tool, not something I would bother my users with. -
@mrjj
Yes, I also read about it, but I want to make it platform independent (all platforms, Qt can support with a desktop application), so unfortunately not the best option...
Well, that story sounds like a lot of fun and @Chris-Kawa yes 23 copies of one interpreter... that hurts. -
wow @Chris-Kawa , i only had 2 extra. Spacewise its no concern but if an app adds it path to the global path and others do too, you have this lovely situation it might use
another version than it came with. I imagine on linux its being less of an issue but
i full agree that an external dependency often is an extra invitation for user support requests. So the fix for a system wide working python is to let all apps bundle one is
indeed awful.@Niagarer
For multiple platform deployment, i would think very, very hard if you could avoid
using python with the c++ program.
If the python programs only scan and replace such %tags%, it might not be so bad in c++ but i suspect you are doing far more. -
Well, to sum it up:
It is technically very possible with embedded python like
https://www.python.org/ftp/python/3.6.3/python-3.6.3-embed-win32.zip
but
@mrjj said in How to use/execute a Python script inside QtCreator C++ project:But if your app is to run on say Mac,Linux AND windows, i would not myself go down the route of including/needing python as its bound to give issues.
There are easy solutions for Windows and if you use the global path to a python interpreter, you should pay attention, that your python script always works with the newest python versions, but then this would be a legitim option.
I also want to refer to the post by Chris Kawa (this first answer post at the top).
If tere is another option I forgot, please answer here and update this post ^^ -
hello, can you tell me how to call python code from qt c++ application? how the python code shall look like and the function that shall be called how shall it be looked like?
-
@marwa-ahmed Do you want to execute an external Python script or do you want to execute Python script inside your application (in same process)?
-
@jsulm
The OP already re-raised this question in https://forum.qt.io/topic/115475/calling-python-from-qt-c, where it has been answered. -
@marwa-ahmed Please do not double-post!