PyQt5 无法连接到显示器 [英] PyQt5 Could not connect to display

查看:84
本文介绍了PyQt5 无法连接到显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了学习 Python,我决定制作一个可以与 Web API 交互的小型 GUI.所以没有多想,我用 Vagrant (ubuntu/trusty64) 创建了一个虚拟机并安装了 PyQt5.我做了一个小脚本来创建一个窗口(这里是)

to learn python I decided to make a small GUI that will interact with a web API. So without much thinking I created a virtual machine with Vagrant (ubuntu/trusty64) and installed PyQt5. I made a small script to create a window (here it is)

import sys
from PyQt5 import QtWidgets

app = QtWidgets.QApplication(sys.argv)

main_window = QtWidgets.QMainWindow()
main_window.show()

sys.exit(app.exec_())

当我执行我的脚本时,我最终遇到了这个错误

When I executed my script I ended up with this error

QXcbConnection:无法连接到显示器

QXcbConnection: Could not connect to display

所以我想问题出在我使用的是没有显示器的虚拟机这一事实.有没有办法让它使用我的 Windows 显示器来渲染我的程序?还是我需要安装一个带有 virtualbox 的虚拟机?

So I guess the problem comes from the fact that I'm using a virtual-machine without a display. Isn't there a way to make it use my Windows display just to render my program? Or do I need to install a VM with virtualbox?

感谢您的时间.

推荐答案

使用 Vagrant 配置 VM 时,您可以指定引导至 GUI,例如:

When provisioning your VM with Vagrant, you may specify to boot to GUI, such as:

config.vm.provider "virtualbox" do |v|
  v.gui = true
end

更多信息此处

这将使用虚拟机的显示启动 Qt 应用程序.

This will then launch the Qt app, using the VM's display.

这篇关于PyQt5 无法连接到显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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