[PyQt] Deploying PyQt in a C++ Application

Phil Thompson phil at riverbankcomputing.com
Thu Aug 6 10:30:25 BST 2015


On 06/08/2015 5:03 am, Ferguson, Eric W (397B) wrote:
> Currently, I am developing a C++ GUI application using the Qt
> framework with OpenGL. Typically this application is driven by user
> mouse/keyboard input. However, we have recently built a python
> interface using PyQt so users can  drive the application with simple
> python scripts. This means that we have an embedded python within our
> C++ application, and whenever a user loads in a python script, that
> script imports another script which makes PyQt calls to access certain
> Qt C++ methods in the application.
> 
> All of this functionality works in my development environment, but now
> I would like to deploy my application without requiring users to have
> PyQt since they will not need to use it directly within their scripts.
> Ultimately I would like to deploy the application on Mac, Windows and
> Linux environments. Since I am completely new to python deployment, I
> did some reading and it seems like I need to include the following in
> my deployment:
> 
>   1.  Python interpreter
>   2.  Python standard libraries – Ideally, we want users to have
> access to all of the standard libraries modules in case they want to
> do complex python programming within their scripts.
>   3.  PyQt
> 
> As a note, right now, I dynamically link in Qt libraries to my
> application and include those DLLs within the application bundle.
> 
> So now for my questions:
> 
>   1.  I read through the pyqtdeploy documentation and it looks like
> this tool has the capability to statically build all three of the
> dependencies listed above. However, that tool seems geared towards
> making complete application binaries. In my case, I would simply want
> these statically built, and then I would go about linking the
> dependencies to my application. Would it be feasible to use the
> pyqtdeploy tool to accomplish my objective?

Yes. The support for building static versions of dependencies is both 
optional and separate. Pick and choose what you need and how you use the 
results.

pyqtdeploy turns your Python code into C++ source code and a qmake .pro 
file so that you can subsequently turn it into an executable 
application. However there is nothing to stop you doing something 
different - say by changing the .pro file to create a shared library 
that you can link into another application.

>   2.  I don’t completely understand the implications of statically
> building the python interpreter on Windows. It sounds like if I build
> python statically, I won’t be able to dynamically import C/C++
> extension modules. Since I want to include most if not all of the
> python standard libraries, and the standard library includes C
> extension modules, then will I have to use a dynamic build of Python
> on windows?

Yes.

>   3.  Let’s say I did not want to build PyQt statically, but instead
> wanted to include it as a set of dynamic libraries. When I installed
> PyQt, it built .so files for each Qt module (QtGui, QtCore, etc.),
> however, those libraries have Qt dependencies that are dependent on
> the location of the Qt C++ libraries on my machine. How can I remove
> the dependencies in those .so files so that they point at a relative
> path, or is that even possible?

Those are issues for Qt and qmake in particular - check out qmake 
support for RPATH and also qt.conf.

Phil


More information about the PyQt mailing list