在没有显示的情况下运行 PyQt4 脚本 [英] Running a PyQt4 script without a display

查看:63
本文介绍了在没有显示的情况下运行 PyQt4 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个 Python 脚本,该脚本通常通过没有 X11 转发的连接远程打开 Qt 窗口.有没有办法创建某种可以将窗口绘图发送到的虚拟显示?(某些 x11 等效于/dev/null).这样做的目的是检查脚本是否可以与 PyQt4 的 API 一起用于不同版本的 PyQt4,但我希望能够在没有显示的服务器上远程运行它.有什么想法吗?

I would like to run a Python script that normally opens a Qt window remotely over a connection with no X11 forwarding. Is there any way to create some kind of virtual display that the window drawing can be sent to? (some x11-equivalent of /dev/null). The purpose of this is to check that a script works with the API of PyQt4 for different versions of PyQt4, but I want to be able to run this remotely on a server with no display. Any ideas?

推荐答案

您可以安装 xvfb 实用程序

You can install the xvfb utility

sudo apt-get install xvfb

然后启动python脚本:

and then start python scripts as:

xvfb-run python myscript.py

或者如果需要从代码启动虚拟显示,还是需要安装xvfb,另外获取pyvirtualdisplay python包

Or if you need to start the virtual display from code, xvfb is still needed to be installed, and additionally get the pyvirtualdisplay python package

pip install pyvirtualdisplay

然后在创建任何 qt 组件实例之前,添加以下内容:

And then before you create any qt component instances, add this:

from pyvirtualdisplay import Display
display = Display(visible=False, size=(1024, 768), color_depth=24)
display.start()

这篇关于在没有显示的情况下运行 PyQt4 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆