One of the constructors of QApplication
takes a boolean argument GUIenabled
.
If you use that, you can instantiante QAppliaction without an X server, but you can't create QWidgets.
So in this case the only option is to use a virtual X server like Xvfb to render the GUI.
Xvfb can be installed and run using these commands (assuming you have apt-get installed). The code in the original question is in a file called render.py
.
sudo apt-get install xvfb
xvfb-run python render.py